How to Access Document Objects Through JavaScript

Let’ have a look towards the example:
  1. <html>  
  2.   
  3.   <head>  
  4.     <title>Accesing document objects</title>  
  5.   </head>  
  6.   <script type="text/javascript">  
  7.   function displayvalue() {  
  8.     var name = document.form.name.value;  
  9.     alert("Welcome:" + name);  
  10.     var address = document.form.address.value;  
  11.     alert("Address:" + address);  
  12.   }  
  13.   </script>  
  14.   <form name="form">  
  15.     Name:<input type="text" name="name" /></br>  
  16.     Address:<input type="text" address="address" /></br>  
  17.     <input type="button" onsubmit="displayvalue()" value="Display name" />  
  18.     <input type="button" onsubmit="displayvalue()" value="Display Address" />  
  19.   </form>  
  20.   
  21. </html> 
Output
 
 
The logic applied in the above example is document.form.name.value;
 
Here, document is the root of the html document, form is the name of the form from where the function displayvalue() will display the name entered by the user, name is the attribute name of the input text and value is the property that returns the value of input text.