R
roohbir
I was going through this code from Negrino's JavaScript for the WWW
book. I have 2 questions:
1. Why has the author used validForm(passForm)? I mean what is
'passForm' in the function?
2. And its relation to this line - <form onsubmit="return
validForm(this)" action="">; What is 'this' here?
Thanks in advance.
Roohbir
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Password Check</title>
<script language="Javascript" type="text/javascript">
<!-- Hide script from older browsers
function validForm(passForm) {
if (passForm.passwd1.value == "") {
alert("You must enter a password")
passForm.passwd1.focus()
return false
}
if (passForm.passwd1.value != passForm.passwd2.value) {
alert("Entered passwords did not match")
passForm.passwd1.focus()
passForm.passwd1.select()
return false
}
return true
}
// End hiding script -->
</script>
</head>
<body bgcolor="#FFFFFF">
<form onsubmit="return validForm(this)" action="">
Your name: <input type="text" size="30" />
<p>Choose a password: <input type="password" name="passwd1" /></p>
<p>Verify password: <input type="password" name="passwd2" /></p>
<p><input type="submit" value="Submit" /> <input type="reset" /></p>
</form>
</body>
</html>
book. I have 2 questions:
1. Why has the author used validForm(passForm)? I mean what is
'passForm' in the function?
2. And its relation to this line - <form onsubmit="return
validForm(this)" action="">; What is 'this' here?
Thanks in advance.
Roohbir
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Password Check</title>
<script language="Javascript" type="text/javascript">
<!-- Hide script from older browsers
function validForm(passForm) {
if (passForm.passwd1.value == "") {
alert("You must enter a password")
passForm.passwd1.focus()
return false
}
if (passForm.passwd1.value != passForm.passwd2.value) {
alert("Entered passwords did not match")
passForm.passwd1.focus()
passForm.passwd1.select()
return false
}
return true
}
// End hiding script -->
</script>
</head>
<body bgcolor="#FFFFFF">
<form onsubmit="return validForm(this)" action="">
Your name: <input type="text" size="30" />
<p>Choose a password: <input type="password" name="passwd1" /></p>
<p>Verify password: <input type="password" name="passwd2" /></p>
<p><input type="submit" value="Submit" /> <input type="reset" /></p>
</form>
</body>
</html>