Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

getElementById


The document.getElementById() method returns the element of specified id.

In the previous page, we have used document.form1.name.value to get the value of the input value. Instead of this, we can use document.getElementById() method to get value of the input text. But we need to define id for the input field.

Let’s see the simple example of document.getElementById() method that prints cube of the given number.

  1. <script type=“text/javascript”>
  2. function getcube(){
  3. var number=document.getElementById(“number”).value;
  4. alert(number*number*number);
  5. }
  6. </script>
  7. <form>
  8. Enter No:<input type=“text” id=“number” name=“number”/><br/>
  9. <input type=“button” value=“cube” onclick=“getcube()”/>
  10. </form>

Output of the above example

Comments

comments