0

How to duplicate input value to another using jQuery

Posted by danblog on July 23, 2010 in Scripts |

Just thought I would post this little jQuery snippet which simply updates the value of input field based on value of another. This can be particularly useful in some situations where information can be duplicated for example perhaps on a billing and shipping address form etc.

Example for standard text based input field:

$(“#src-field”).change(function () {
$(“#otherfield”).val($(“#src-field”).val());
})
.change();
Example for select field:
$(“#src-select”).change(function () {
$(“#otherfield”).val($(“#src-select option:selected”).val());
})
.change();

The Select version will used the selected value, if you would like to get the text of the option you can replace .val() with .text().

Hope this helps someone, would appreciate a quick comment if you use it!

Tags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © 2007-2017 Dan's Tech Blog All rights reserved.
This site is using the Desk Mess Mirrored theme, v2.5, from BuyNowShop.com.