Javascript examples for DOM HTML Element:Input Text
Set input text box value using setAttribute() method
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//from ww w . j a va2 s. c o m var field = document.getElementById('textfield'); var value = 'Some text'; field.addEventListener("click", function () { this.setAttribute('value', value); }); } </script> </head> <body> <input id="textfield" type="text"> </body> </html>