Tuesday, September 20, 2011 Cloning form values using jQuery
This simple example shows how you can copy form values using jQuery from one fieldset to another.
In the example the values from the Address fieldset are copied to the Billing Address fieldset when the Use Same Address checkbox is ticked.
Firstly, create the following form.
Now copy the following jQuery code and paste it below the form.
Boom! That's it!
Tags
Share
Comments
Tuesday, September 20, 2011 John Whish
@Simon,
You could use a loop as you're using a naming convention to reduce some code:
$.each(['address','town','county','postcode'], function(i,v){
$('#billing'+v).val($('#'+v).val());
});
Also for the jQuery 'ready' you could do:
jQuery(function($){
.. stuff ..
});
- John
Tuesday, September 20, 2011 Simon Bingham
Thanks John. That's some 'bad-ass' jQuery you've written there! :)