deemi deemi - 1 year ago 107
Javascript Question

Input fields issue on prepend in jQuery

I am working on a meta fields in

. The scenario is, there is a question field and its answer field, Like this:

enter image description here

When I click on plus sign the answer field add successfully with

But I face an issue with prepend. When I enter a value in answer field and click on plus the input field in which I enter the value does not goes down but new field prepend blew, Like this:

enter image description here

js Fiddle

I want, that when I enter the brown and click on plus sign the brown goes down and first on is empty, Like This:

enter image description here

Answer Source

You are not adding value in the input field while appending.

var result_a = jQuery('#qs_survey_a').val();
        jQuery('.multi_fields_wrap').prepend('<div class="multi_fields"><input type="text" name="qs_survey_a[]" id="qs_survey_a" value="' + result_a + '"><a href="#" class="qs_cross">x</a></div>');

First get the value of input field and then add that value while appending the new row. You can also clear the input field after the prepending event takes place by adding this simple line


Hope That Helps

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download