How to access the form in JavaScript?
To access the form within page we use the following statement.
Document.formname.elementname
Now we create a form on the page and give the name of that form like this.
<form name="Form1">
<input type="text" size="10" value="good" name="txt"><br /><br />
</font>
Form name and element name must be different. In this example form name is 'Form1' and element name is 'txt'.
For Example:
<html>
<head>
<title>Access the form</title>
</head>
<body bgcolor="#cc9933">
<form name="Form1">
<input type="text" size="10" value="good" name="txt"><br /><br />
<input type="button" value="Continue"onclick="alert(document.Form1.txt.value)">
<font color=navy><p>(Click on this button to access the value)</p>
<p>Fill the other value in the textbox and again click on the button you will see different value in the alert box.</p>
</font>
</form>
</body>
</html>
Output:

Figure 1: Display the form.
Fill the value in textbox and click on the button, value will access in the alert box like this:

Figure 2: Accessing the value from the text box.
Note: When you create a form, always remember to give both the form name and element name should be distinct.