I need help with this checkbox validation. Complex! (at least for me)

C

Czarina

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.
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.

Please help!

Thanx so much!

Czarina Mir
 
M

Michael Winter

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top