Use JavaScript variable in html - Javascript Language Basics

Javascript examples for Language Basics:HTML

Description

Use JavaScript variable in html

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <input type="text" id="userInput"> 
      <input type="button" id="button" onclick="loader();" value="do"> 
      <div id="placeholder">
         test//from  www  . jav  a  2 s  .  c  o m
      </div> 
      <script>
function loader()
{
  var my = document.getElementById("userInput").value;
  document.getElementById("placeholder").innerHTML=my;
}

      </script>  
   </body>
</html>

Related Tutorials