Discussion Locked

Form Field Validation not working

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am trying to implement a field validation function:

function validate()
{
var result = true;
var field=document.problem_form.explanation.value;
if ((x==null) || (x.length==0))
{
alert("Please enter an explanation");
result = false;
}
return result;
}

Now if the field is empty, it will display the alert window, but it will also perform the FORM ACTION. I can't figure out why. Is there some special situation that will make it perform the ACTION that I just happen to be in? Anyadvice would be great.

Thanks,
Jeff Krause

2 replies

by ferg2001

function validate()
{
var field=document.problem_form.explanation.value;
if ((field==null) || (field.length==0))
{
alert("Please enter an explanation");
return false;
}
return true;
}

When calling the function inthe form, use

by bisso

Hii,
One and all.
I think your function should end with.

return false;

and the variable "result" as only parametre:
function validate(result) {
// your code here
}

and call your function:
validate(x); x will return with result value.
have fun Jeff:

Bisso.

This discussion is closed to new replies.