Reference form element by using the dot notation : Elements « Form « JavaScript Tutorial






<html>
<head>
<title>Displaying the value entered in a text field</title>
<script type="text/javascript" language="javascript">
<!-- //
function DisplayValue(){
    if(document.MyForm.MyTextField.value!==""){
        alert("The value entered was \n" + document.MyForm.MyTextField.value);
    }
    else{
        alert("The text field was empty!\nPlease enter your name.");
    }
}
// -->
</script>
</head>
<body>
<form name="MyForm" action="http://www.java2s.com/" method="Post" onsubmit="DisplayValue()">
<input type="text" name="MyTextField"/><P>Enter your name</p>
<input type="submit" value="Click to Submit"/>
</form>
</body>
</html>








10.4.Elements
10.4.1.Accessing and Writing Information
10.4.2.Writing information to forms.
10.4.3.Reference form element by using the dot notation
10.4.4.Loop through all elements in a form
10.4.5.Check Form element type