How to copy text from one input textbox to multiple textboxes using jQuery
In this post, find jQuery code to copy text from one input textbox to multiple textboxes while typing or in real time or on paste. To achieve this, give a same class name to all the textboxes in which text needs to be copied.
For example, in the below code all the textboxes are having same class named "copyText".
<input type='text' id='txtFirst' class='copyText' /><br/> <input type='text' id='txtSecond' class='copyText' /><br/> <input type='text' id='txtThird' class='copyText' /><br/>
Now, attach "keyup", "change" and "paste" event on "copyText" class and then assign the current input value to all other textboxes.
$(document).ready(function(){ $('.copyText').on('keyup change paste', function(e){ $('.copyText').val($(this).val()) }); });
You may also like:
- Disable Cut, Copy and Paste function for textbox using jQuery
- How to Limit Number of Characters in Textarea using jQuery
- How to set focus on next textbox on Enter Key using jQuery
- jQuery plugin for Uppercase, lowercase, title case and pascal case
Above code will keep all the textboxes in sync. But if you want to copy text from first input to all others not vice-versa then attach "keyup", "change" and "paste" event on first input text only.
$('#txtFirst').on('keyup change paste', function(e){ $('.copyText').val($(this).val()) });
Feel free to contact me for any help related to jQuery, I will gladly help you.