Set value to Input text field with setAttribute via <p> element onclick - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Paragraph

Description

Set value to Input text field with setAttribute via <p> element onclick

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>SO - 27311063 - javascript onclick</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function myFunction(){/*from w  w w .ja v a 2  s .c  om*/
var elem = document.getElementById("query"); // Get text field
elem.setAttribute('value','Insert a correct email');
}

      </script> 
   </head> 
   <body> 
      <input type="text" id="query" name="quer"> 
      <p id="demo" onclick="myFunction()">Click Here</p>  
   </body>
</html>

Related Tutorials