469,602 Members | 1,845 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

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

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
Jul 23 '05 #1
2 1279

Czarina <dp*****@planninggroup.com> wrote in message
news:93**************************@posting.google.c om...
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


Hi,
clicked on the link
http://www.gainesvillewebs.com/czar...h_results-2.htm
and it says the page cannot be displayed.
Is the URL correct ?
chris
Jul 23 '05 #2
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)
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by SStory | last post: by
18 posts views Thread by Q. John Chen | last post: by
4 posts views Thread by timothy.pollard | last post: by
1 post views Thread by oakura_ape | last post: by
1 post views Thread by theresa | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.