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

Forum

Log In Sponsors
Board index Programming JavaScript Forum

OnSubmit Event

OnSubmit Event

Postby Lana on Sun Aug 16, 2009 11:53 pm

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: Sun Aug 16, 2009 11:40 pm

Who is online

Users browsing this forum: No registered users and 10 guests