Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Copy text field's value from a different form into another form's text field

I have two forms.

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

Text field names and ids are different.

How can I achieve this?

This didn't work:

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

Thanks!

like image 265
Claudio Delgado Avatar asked Feb 25 '13 16:02

Claudio Delgado


2 Answers

If you're asking for jQuery you could try:

$("#name").val($("#user").val());
like image 132
Corey Avatar answered Sep 24 '22 12:09

Corey


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

$(document).ready(function()
{
    $('#btn1').click(function()
    {
         $('#field2').val($('#field1').val());
    });
});
like image 25
LiamB Avatar answered Sep 23 '22 12:09

LiamB