javascript thread: Almost got it, please have a look at this one.
looks like the problem is that your function ValidateForm() ALWAYS returns false.
I think you will want to return true if there are no errors and false if there are errors.
one way to handle this would just be to wrap all your code in a larger test case -
function ValidateForm(){
var uname = document.login.username.value;
var pword = document.login.password.value;
if (uname == "" || pword == ""){
if (uname == "") {
vusername.innerHTML = "<font color=red>This field is
required</font>"
}
if (pword == "") {
vpassword.innerHTML = "<font color=red>This field is
required</font>"
}
if (uname == "") {
vErrorMessage.innerHTML = "<font color=red><br><br>Errors have
been found whilst trying to log you in.</font>"
}
return false;
}
// else if uname != "" && pword != ""
return true;
}
hth,
Arthur Gaisin
---- Message from "Al Higgs" <al.higgs@b...> at Sun, 17 Feb 2002 20:42:57 ------
Hello,
I have almost got a validation script working just as i want it but there
is one problem, hope someone can help cause im baffled!!!
The function is as follows:
<script language="JavaScript">
function ValidateForm() {
if (document.login.username.value == "") {
vusername.innerHTML = "<font color=red>This field is
required</font>"
}
if (document.login.password.value == "") {
vpassword.innerHTML = "<font color=red>This field is
required</font>"
}
if (document.login.username.value == "") {
vErrorMessage.innerHTML = "<font color=red><br><br>Errors have
been found whilst trying to log you in.</font>"
}
return false
}
</script>
Then the onSubmit script is
onLoad="return ValidateForm()"
Problem is, if fields arent entered as required the error message appears
next to the relevant text box as i want it to, BUT, if the user then fills
in that field they arent able to submit the form, it just wont let them????
Any ideas??