Copy multiple input fields to other matching input fields with jQuery/Javascript -


i have dummy form , actual form in @ point want copy input values dummy form across real form. dummy fields have same names real form (so can match them up).

so in dummy form:

<input name="item1" value="field1" /> <input name="item2" value="field1" /> <input name="item3" value="field1" /> 

and in real form:

<input name="item1" value="" /> <input name="item2" value="" /> <input name="item3" value="" /> 

i assume i'll need iterate on each input in dummy form (using jquery .each() ?) while collecting name , value in js object. iterate on each input in real form, matching name selector , setting value (perhaps can done in 1 .each() function ???)

i've started following code grabs values (and index) array, because need 2 values (name , value, , index irrelevant) assume i'll need object not array, not sure begin that.

var inputvalues = [];     $("#dummyform input").each(function() {         inputvalues.push($(this).val());     }); 

any or advice appreciated.

map them like

$('#dummyform [name]').each(function() {    var name = $(this).attr('name');    $('#realform [name="' + name + '"]').val($(this).val());  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>  <form id="dummyform">    <input name="item1" value="field1" />    <input name="item2" value="field2" />    <input name="item3" value="field3" />  </form>  <form id="realform">    <input name="item1" value="" />    <input name="item2" value="" />    <input name="item3" value="" />  </form>


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -