Form Objects and Elements



Write a javascript code to demonstrate getElementById() and method.

<html>
  <head>
    <title>Accessing Elernrts by ID</title>
      <script>
      
        function check()
      {
          var i = document.getElementById("myText");

          if(i.value != "")

            alert("You entered : "+i.value)

        else

            alert("please enter some text")
      }

      </script>
    </head>
  <body>

<form action="" method="post" name="entry">

      <input type="text" id="myText"/>

      <input type="button" onclick="check()" value="Checker"/>
       
    </form>        
  </body>
</html>

Output: