This Message Forum is no longer in use

Please use the new Bravenet Help Forums FOUND HERE

General Forum
This Forum is Locked
Author
Comment
Validation not working

Hello,
I'm having trouble getting validation to work on my web site.
Basicly I'm trying to validate whether or not a name has been entered or not.
The problem I am having is that when I leave the required field blank and hit the submit button, the form submits rather than sending a message saying that a name is required.
The page is at:
http://einstein.franklin.edu/~nickel08/Validate/validate.htm
and the .js code is:

Code:

window.onload = startForm;
function startForm() {
document.forms<img src="//images.bravenet.com/common/images/smilies/0.gif" border="0" alt=""> .onsubmit = checkForm;
}
function checkForm() {
if (document.forms<img src="//images.bravenet.com/common/images/smilies/0.gif" border="0" alt=""> .fname.value.length == 0)
{alert("You must enter a name");
return false;}
else return true;
}

function startForm(){
}

I posted the code because i can't think of any other way to let you all see it, since its actually a .js file.
Oh and by the way, for some reason some of the elements on the page only work if you are using or emulatuing windows xp.
Thanks for any help.
-Chris

Browser: IE 7

OS: Windows Vista Home Premium with Service Pack 1 64 bit

Re: Validation not working

You would have been better off not posting the Javascript. The forum messes it up so that it's unusable from your posting. When someone downloads your web page to test the code, they get the Javascript anyway.

With the code you provided, if the "Name:" input field truly has nothing in it, the validation script works. But that is not to say it is fool proof. Because you are only looking at the character count to know whether there is anything entered, a single space character will count as one character. A single space will allow the form to submit.

But using Javascript for this kind of thing is not necessarily a good idea. It's very easy to defeat Javascript by simply turning it off. Then, none of the validation will work, but submission will still probably work. At least, it will try to happen. In your "form" tag you use a "mailto:" action parameter. While it is correct and is still proper code, that kind of thing hasn't been useful in over 10 years. Maybe longer. The "mailto:" action parameter depends on the visitor having a fully configured email client on their PC. Over the years, most users have switched over to some form of web based email. Probably, only about 5 percent of your visitors that try to use your form, will have the necessary configuration to get it to work. The rest will either give up or extract your email address from the form and send it manually.

Since you don't have and advertisements on your page, I assume you have paid hosting. In that case you should be able to use a PHP validation script that will also take care of email. This is more difficult for someone to defeat and has the added advantage of hiding your email address. As it is, the email address in your form is only useful to spammers. Complete, free, PHP scripts to handle forms are available all over the internet. Just pick one that suits your needs. Just put the string "php form validation scripts" in a Google search. You will get lots of hits.

Browser: Firefox, Netscape, Sea Monkey, Internet Explorer, .....

OS: Solaris (Sparc,x86), Linux, XP