I have to write Validate function only according to the following instructions. I don't understand how onsubmit = "return Validate(this)" works. I appreciate your input, guys.
Complete the JavaScript validation function “Validate” in an HTML page. The function should return true if the form field “name” is not empty and the checkbox is checked. Otherwise, it should pop up a message to ask a user to fill in the fields and return false.
<script type=”text/javascript”>
function Validate()
{
var name = document.myForm.name.value;
var agree = document.myForm.agree.value;
if((name == null && agree == null)||
(name != null && agree == null)||
(name == null && agree != null))
{
window.alert("Please fill in the fields!");
return false;
}
else
{
return true;
}
}
</script>
</head>
<body>
<form name = "myForm" action="submit.php" method="post" onsubmit = "return Validate(this)">
Your Name:
<input type="text" name="name" value="" />
<input type="checkbox" name="agree" /> I agree<br />
<input type="submit" name="mysubmit" value="Submit"/>
</form>


