On 7 Apr 2004 11:44:47 -0700, Czarina <dp*****@planninggroup.com> wrote:
hi guys!
here I am again, bugging you
Here is where my page stands right now:
http://www.gainesvillewebs.com/czar...h_results-2.htm
The top 2 forms are working just fine, but the bottom one, with the
check boxes, it not working
I am by NO MEANS, a Javascript expert, so please be patient!
Here is what it needs to do:
It need to check that at least 1 checkbox is selected, and if not,
display error message.
function isChecked( form, name ) {
var g = form.elements[ name ];
for( var i = 0, n = g.length; i < n; ++i ) {
if( g[ i ].checked ) {
return true;
}
}
return false;
}
function validate( form ) {
if( !isChecked( form, checkboxes )) {
alert( 'Your message here' );
return false;
}
// Perform other validation here. Return false if
// conditions fail.
}
<form ... onsubmit="return validate(this);">
...
</form>
Where "checkboxes" above is a string that contains the name of the group
of checkboxes.
Also, every form needs to do an OnFocus on the element that needs to
be filled out, at the same time that the error pops.
If you want to move the screen to the failed control, call the focus()
method on that control. For example (modifying validate(), above):
function validate( form ) {
if( !isChecked( form, checkboxes )) {
// Move focus to the first checkbox in the group
form[ checkboxes ][ 0 ].focus();
alert( 'Your message here' );
return false;
}
// Perform other validation here. Return false if
// conditions fail.
}
Some browsers render focus differently, and users might not be able to see
any particular highlight, especially with checkboxes.
Hope that helps,
Mike
--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)