Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Greetings experts of Codeproject.

I have a task to copy the contents of one textbox into another textbox.

The following works by adding to value of textbox1 one to textbox2:

<html>
<head>
<script src="jquery_min.js">
</script>
<script>
$(document).ready(function(){
$("#button").click(function(){
var ravi=$("#text2").val();
 $("#text1").val(Testing);
 });
 });
 </script>

 </head>
  <body>
 <input type="text" value="Testing" id="text">
 <input type="text" id="text1">
 <input type="button" value="Copy" id="button">
  </body>
  </html>


However, is it possible to do this without manually putting the value of textbox1 in the javascript?

What I have tried:

This is what I have tried so far:

<pre><html>
<head>
<script src="jquery_min.js">
</script>
<script>
$(document).ready(function(){
$("#button").click(function(){
var ravi=$("#text2").val();
 $("#text1").val(Testing);
 });
 });
 </script>

 </head>
  <body>
 <input type="text" value="Testing" id="text">
 <input type="text" id="text1">
 <input type="button" value="Copy" id="button">
  </body>
  </html>
Posted
Updated 1-Jul-21 22:18pm

1 solution

Simple:
JavaScript
$(function(){
    $("#button").click(function(){
        var value = $("#text2").val();
        $("#text1").val(value);
    });
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900