
Originally Posted by
leighgoodman
if ( (strRetailStores[0].checked == false ) && (strRetailStores[1].checked == false ) )
How is the identifier, strRetailStores, defined? That is most likely the cause of your problem.
A general function can be used for this:
Code:
function getCheckedButton(group, form) {
if (typeof group == 'string') group = form.elements[group];
for (var i = 0, n = group.length; i < n; ++i)
if (group[i].checked) return group[i];
return null;
}
where the first argument is either a collection of radio buttons, or the name of the button group. The second argument is a reference to the containing form, though its only necessary if a string is used for the first argument.
Given a reference, form, you could check the group with either of the following expressions.
Code:
getCheckedButton(form.elements.retailStores)
getCheckedButton('retailStores', form);
If null is returned, no button in the group was checked.
Be aware that a group of radio buttons should always have one control checked; one of the controls should possess a checked attribute.

Originally Posted by
codeexploiter
<form ... onSubmit="return validate();">
It is wise for references to the control or form to be passed directly to validation functions:
Code:
<form ... onsubmit="return validate(this);">
At the very least, this simplifies accessing controls. It also makes some identifiers unnecessary.
<input type="submit" name="submit" value="submit">
Naming submit buttons "submit" is not a good idea: it overwrite the submit method of the form.
var o = document.getElementById('one');
var t = document.getElementById('two');
Don't use the getElementById method to access form controls within a form. Use the elements collection of the latter, instead.
Mike
Bookmarks