Loading ...

JavaScript: How to set one textbox value with other textbox value

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  client side web development   » JavaScript: How to set one textbox value with other textbox value

JavaScript: How to set one textbox value with other textbox value

Posts under the topic: JavaScript: How to set one textbox value with other textbox value

Posted: 10/10/2011

Lurker 100  points  Lurker
  • Joined on: 9/11/2010
  • Posts: 20

Hi,

I have two textboxes on my page say textbox1 and textbox2. Now I want to set the value of textbox2 with the value of textbox1 on button's click. Can you help me do that?


Posted: 10/11/2011

Lurker 270  points  Lurker
  • Joined on: 1/3/2009
  • Posts: 14

Hi,

You can use jquery to set value of a textbox into another text box  

<input type="text" id="textBox1"/>
 <input type="text" id="textBox2"/>
 <input type="submit" id="btnclick"/>
$('#btnclick').click(function (e) {        
        var textBox1 = $('#textBox1');
        var textBox2 = $('#textBox2');
        textBox2.val(textBox1.val());
    });




Posted: 10/11/2011

Guru 16773  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Title</title>
</head>
<body>
    <form id="HtmlForm" runat="server">
    <input type="text" id="txt1" />
    <input type="text" id="txt2" />
    <input type="button" id="btnTest" onclick="foo()" value="Test"/>
    </form>
    <script type="text/javascript">
        var foo = function () {
            document.getElementById("txt2").value = document.getElementById("txt1").value
        }
    </script>
</body>
</html>


Page 1 of 1 (3 items)