• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Created a function that will display what is written in textbox, but it is not working

 
Vishal Hegde
Ranch Hand
Posts: 1077
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ranchers,

Below is the html code saved in abc.html




where Am i going wrong?
 
RatiKanta pal
Ranch Hand
Posts: 88
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

<!DOCTYPE html>
<html>
<head>
<script>
function copyText()
{
document.getElementById("field2").value=document.getElementById("field1").value;
alert("hiii");
}
</script>
</head>
<body>
<form name="hello" onsubmit="">
Field1: <input type="text" id="field1" value="Hello World!"><br>
Field2: <input type="text" id="field2">
<br><br>
<input type="button" onclick="copyText()" name="click" value="click">

<p>A function is triggered when the button is clicked. The function copies the text in Field1 to Field2.</p>
</form>
</body>
</html>




And in your code var x=document.getElementById('text1').value part is missing

thank you.
 
Alok Agrawal
Greenhorn
Posts: 14
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.value is missing is line no. 8, it should be like:

 
RatiKanta pal
Ranch Hand
Posts: 88
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Yes .value will extract the data from "text1" id.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic