How to Access Document Objects Through JavaScript

Let’ have a look towards the example:

<html>
<head>
<title>Accesing document objects</title>
</head>
<script type="text/javascript">
function displayvalue()
{
var name=document.form.name.value;
alert("Welcome:"+name);
var address=document.form.address.value;
alert("Address:"+address);
}
</script>
<form name="form">
Name:<input type="text" name="name"/></br>
Address:<input type="text" address="address"/></br>
<input type="button" onsubmit="displayvalue()" value="Display name"/>
<input type="button" onsubmit="displayvalue()" value="Display Address"/>
</form>
</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.

Ebook Download
View all
Learn
View all