It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Partner Sites
Board index Programming JavaScript Forum

OnSubmit Event

OnSubmit Event

Postby Lana on Mon Aug 17, 2009 12:53 am

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>
Lana
 
Posts: 1
Joined: Mon Aug 17, 2009 12:40 am

Return to JavaScript Forum

Who is online

Users browsing this forum: No registered users and 4 guests