Get input text box value in JavaScript - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

Get input text box value in JavaScript

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <div> 
         <form align="center" method="post"> 
            <input id="mainText" type="text" align="center" placeholder="Search"> 
            <input type="submit" onclick="myFunction()"> 
         </form> 
      </div> 
      <script>
function myFunction(){/*from w  w w  . ja v a  2s.  c om*/
    $a= document.getElementById("mainText").value;
    console.log($a);
        }

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

Related Tutorials