Pass script tag value to input tag in html - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Form Event

Description

Pass script tag value to input tag in html

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(){// ww  w.j  av a 2 s  . co 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