• 0

Form Validation using Javascript... help please!


Question

Hi there. I am hand coding in Javascript a form validation to make certain fields required.

I have the form working fine, the validation working fine, however, when I try to validate a checkbox, it just won't work. I know there is something I am missing, so I'd love for someone to check it out. Here's the page with the form:

http://www.crosscountryrates.com/free_analysis.htm

I know the coding for the page isn't beautiful, but that's not what I want comments on... just why the heck the very first checkbox (the "Agreement") won't validate properly like the other ones do. More specifically, what's the value of the checkbox when it's not checked? How can I test it in an "if" loop to let the form validator know if someone hasn't checked it? Through testing I found that the checkbox has the value "agree" whether you check the box or not. Why?

Thanks for your help.

Here's where I declare the checkbox in the html

<input type="checkbox" value="agree" name="agreement">

Here's the javascript test:

if (agreement.value != "agree")

{

window.alert("You must accept the agreement.");

agreement.focus();

return false;

}

(oh and I know, "haha", nice signature Lundy)

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.