A Pen by Captain Anonymous on CodePen.
Created
April 10, 2015 15:06
-
-
Save anonymous/7c63715e451acb4e76ba to your computer and use it in GitHub Desktop.
pvXdWO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form id="form1"> | |
<input name="name" value="Zac"> | |
<input name="address" value="407 French Road"> | |
<select name="gender"> | |
<option></option> | |
<option selected>Male</option> | |
<option>Female</option> | |
</select> | |
</form> | |
<button id="copy_button">Copy →</button> | |
<form id="form2"> | |
<input name="name" value=""> | |
<input name="address" value=""> | |
<select name="gender"> | |
<option></option> | |
<option>Male</option> | |
<option>Female</option> | |
</select> | |
</form> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#copy_button').click(function(){ | |
copyFormValues( $('#form1'), $('#form2') ); | |
}); | |
function copyFormValues ( $source_form, $target_form ) { | |
$source_form.find(':input').each(function(){ | |
var field_name = $(this).attr('name'), | |
field_value = $(this).val(); | |
$target_form.find('[name='+field_name+']').val(field_value); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment