Set input text box value using setAttribute() method - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

Set input text box value using setAttribute() method

Demo Code

ResultView the demo in separate window

<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>

Related Tutorials