471,898 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,898 software developers and data experts.

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 1383

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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.