views:

779

answers:

4

Form validation for check boxes only seems to be working in IE....? Anyone have a sample of it working in FF?

Thanks.

A: 

Um...Your question isn't exactly a clear one.

If it's form validation as in checking then shouldn't you be doing this server side? Which would be browser independent.

If you are doing any form validation with Javascript and then passing it to the server you must always check it server side as well...a simple http request could easily mess up a system that doesn't.

If you have a Javascript library that you are using to validate forms then it might be an idea to provide more details.

Jamie Lewis
A: 

Just checking on browser side for now. I do not have a JS library, would like to keep it as simple as possible. Like I said I am able to get basic JS functions to validate in IE (alert box if nothing is selected) but in FF it just goes past it and submits.

Using html for form, (js for validation onsubmit(form)....etc..)

Tommy
+1  A: 
var isChecked = document.forms['myform'].elements['mycheckbox'].checked;
if (!isChecked) {
  alert('You must agree');
}
grom
A: 

To obtain your element (checkbox) value, you can use something a bit more cross browser compatible....

var CheckBox = document.all ? document.all["checkbox"] : document.getElementById("checkbox"); var isChecked = CheckBox.checked;

Jobo
Please - never ever use document.all unless you are writing a method to specifically overcome IE's buggy document.getElementById() method.
scunliffe
Well microsoft support and use this notation for cross browser compatibility, if you think its a problem, take it up with them.
Jobo