Copy Form Input Data to Another Input Field with jQuery

This is a very simple example how to copy form input data to other form fields. This is useful when the same information entered can be used in other fields such as shipping and billing address forms.

jQuery

$(document).ready(function(){
	$("input#same").click(function(){
		if ($("input#same").is(':checked'))
		{
			// Checked, copy values
			$("input#shipping-email").val($("input#email").val());
			$("input#shipping-name").val($("input#name").val());
			$("input#shipping-phone").val($("input#phone").val());
		}
		else
		{
			// Clear on uncheck
			$("input#shipping-email").val("");
			$("input#shipping-name").val("");
			$("input#shipping-phone").val("");
		}
	});
});

HTML

<form>
Billing
Email:<input id="email" name="email" type="text" value="test@example.com" />
Name:<input id="name" name="name" type="text" value="John Smith" />
Phone:<input id="phone" name="phone" type="text" value="(123) 456-7890" />

Shipping
Same?:<input id="same" name="same" type="checkbox" />
Email:<input id="shipping-email" name="email" type="text" />
Name:<input id="shipping-name" name="name" type="text" />
Phone: <input id="shipping-phone" name="phone" type="text" />
</form>

Demo and Download

View a demo here

Download

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

Related Posts

Tags: , , ,

Comments (3)

  1. Very nice information. Check out my blog, I just posted my review of the Awesome free Internet Marketing and SEO tools.
    Its a followup to my original post:

    http://blogging-to-make-money.com/search-engine-optimization-awesome-new-tools/

    Anyways here are the actual reviews and links to the free online tools

    Thanks and hopefully this will help you along your travels:

    http://blogging-to-make-money.com/free-google-internet-marketing-and-search-engine-optimization-tools

  2. G says:

    Works great but how do you get it to copy a dropdown….say for the country?

Leave a Reply





Donate

If you found this article useful and would like to see more like it this please consider making a donation.

Sponsors