Skip to content

Instantly share code, notes, and snippets.

Created April 10, 2015 15:06
Show Gist options
  • Save anonymous/7c63715e451acb4e76ba to your computer and use it in GitHub Desktop.
Save anonymous/7c63715e451acb4e76ba to your computer and use it in GitHub Desktop.
pvXdWO
<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 &rarr;</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>
$('#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