How to Assign Value to Textbox Using JavaScript

To assign a value to textbox in JavaScript, we make use of value property.  Example is given below.

<html>
<head>
<title>JavaScript Tutorial </title>
 
<script type="text/javascript">

 function AssignValue()
{
	var n1 = 10;
	var n2 = 50;
	var total = n1+n2;

	//Assigning value to textbox.
    	document.getElementById("myText").value = total;
}

 </script>
</head>
<body>

<input id="myText" type="text" />
<input type="button" value="Assign" onclick="AssignValue()"/>
 
</body>
</html>

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •