Often when creating a form on a web page, I need our customers to fill out a field such as a permanent address, as well as a present address. Instead of having our customers fill out the form twice,I can use JavaScript to copy the form's data from one field to another.
try this....
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>JS Bin</title> </head> <script> function myFunction(){ console.log(this); document.getElementById('permanentaddress').value = document.getElementById('address').value } </script> <body> Address: <textarea id="address"></textarea><br /> permanent address:<textarea id="permanentaddress" onfocusin="myFunction()"></textarea> </body> </html>
$("#txt2").on("focus",function(){ $("#txt3").val($("#txt1").val()); }); $("#txt2").on("input",function(){ $("#txt3").val(''); var res=$("#txt1").val()+' '+ $(this).val(); $("#txt3").val(res); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" id="txt1" /> <input type="text" id="txt2" /> <input type="text" id="txt3" readonly />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.