JQuery Copy text field value from another form to another form text field

I have two forms.

I want to copy the value of one of the text fields in form 1 to another in form 2.

Text field names and identifiers are different.

How can i achieve this?

This did not work:

document.getElementById('name').value = document.getElementById('user').value; 

Thanks!

+4
source share
3 answers

If you are querying jQuery, you can try:

 $("#name").val($("#user").val()); 
+15
source

http://jsbin.com/exudif/2/

 $(document).ready(function() { $('#btn1').click(function() { $('#field2').val($('#field1').val()); }); }); 
+2
source

To get the value using jquery.it, you need to do this. Also make sure that you specify the identifier on the input fields.

like this: <input type='text' name='user' id='user' >

Then only this code will work correctly

 $(document).ready(function() { $('#buttonElement').click(function() { $('#name').val($('#user').val()); }); }); 
0
source

All Articles