-
Netscape and javascript
Why doesnt this work when brosing with Netscape 6:
Nothing happens, the validation never executes!
<script ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function form1_onsubmit() {
//Check that NO fields are BLANK
if (form1.UserID.value == ""){
window.alert ("Username must be entered!");
form1.UserID.value = "";
form1.UserID.focus();
return false;
}
if (form1.password.value == ""){
window.alert ("Password must be entered!");
form1.password.focus();
return false;
}
}
//-->
</script>
-
I wasn't aware you could do that sort of event handler on netscape
-
type javascript: in the location bar to find out what error is
occuring. Then post what you get ;)
-
ahah, on reflection you need to do this!
Code:
<html>
<head>
<script>
function validateInput() //Check that NO fields are BLANK
{
if (form1.UserID.value == "")
{
window.alert ("Username must be entered!");
form1.UserID.value = "";
form1.UserID.focus();
//return false;
}
else if (form1.password.value == "")
{
window.alert ("Password must be entered!");
form1.password.focus();
//return false;
}
else
{
document.form1.submit(); //all is well lets submit our form
}
}
</script>
</head>
<body>
<form name="form1" method="get" action="your.cgi" onsubmit="false; validateInput()">
<input type="text" name="UserID">
<input type="text" name="password">
<input type="submit" value="submit">
</form>
</body>
</html>
haven't checked that code but am confident that it the solution you are aiming for :cool:
-
1) Use vBulletin code tags.
2) Netscape should have a debugger in it.
3) You haven't set form1 to a value, so I don't expect it to work. If you want to call apon the form named form1 in your document, then use document.forms[0], document.forms["form1"], document.getElementsByName("form1")[0], et al. And as always, RTFM.
-
Inaccuracies in that last post of mine here is a functional version !
Code:
<html>
<head>
<script language="javascript">
function validateInput(my_form) //Check that NO fields are BLANK
{
if (my_form.UserID.value == "")
{
window.alert ("Username must be entered!");
my_form.UserID.value = "";
my_form.UserID.focus();
return false;
}
else if (my_form.password.value == "")
{
window.alert ("Password must be entered!");
my_form.password.focus();
return false;
}
else
{
//all is well lets submit our form
return true;
}
}
</script>
</head>
<body>
<form name="form1" method="get" action="your.cgi" onSubmit="return validateInput(document.form1)">
<input type="text" name="UserID">
<input type="text" name="password">
<input type="submit" value="submit">
</form>
</body>
</html>