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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<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> |