Pass Textbox Value to Another Textbox Using jQuery

Last Updated on April 15, 2024 by Roshan Parihar

To update textbox value while typing on another textbox in jQuery, you can use the on('input') event with val() function.

You can also choose to use the keyup() event of jQuery to set value of textbox on keyup on another textbox.

Let’s see some useful examples.

Set Value of Textbox on Typing another Textbox Using oninput Event jQuery

When someone input some text on first textbox, it automatically set the value on another textbox while typing. You can use the on(‘input’) event with val() function.

Test the below example live to see the two input text boxes and type on first box to set it on another.

Test it Live

This is useful when you have several textboxes and want to update some text box while typing on one.

Using Keyup Event in jQuery

In addition to the above example, you can also update one text box value with another using keyup event of jQuery. It updates the second textbox value after typing on first.

See the live example with the button given below.

Test it Live

Both the above examples can give you same result of input to update textbox in jQuery. The first example using on('input') event with val() function set value while typing. However, the keyup event updates the value of another after typing on one text.

Out of these method, on('input') event with val() function will be the preferred one.

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.