Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying data from one text box to another using JavaScript

Tags:

javascript

I want to copy data from one text box to another in html automatically i.e., as I edit the first text box the second one should reflect the same spontaneously.

like image 885
joe Avatar asked Jan 29 '26 16:01

joe


1 Answers

call javascript function on onkeypresss

function copy_data(val){
 var a = document.getElementById(val.id).value
 document.getElementById("copy_to").value=a
}

EDITED USE onkeyup or onblur instead

<html>
<head>
    <script>
    function copy_data(val){
     var a = document.getElementById(val.id).value
     document.getElementById("copy_to").value=a
    }    
    </script>
</head>
<body>
<input type="text" name ="a" id="copy_from" onkeyup="copy_data(this)"/>
<input type="text" name ="a" id="copy_to"/>
</body>
</html>
like image 194
Salil Avatar answered Jan 31 '26 05:01

Salil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!