Created
December 28, 2009 14:30
-
-
Save preaction/264697 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** oneCheckboxIsCheckedInForm( form, message, matchName ) | |
| * Returns true if at least one checkbox in the form is checked | |
| * Will show an alert message otherwise | |
| * Use in an onsubmit handler thus: | |
| * return oneCheckboxIsCheckedInForm(this) | |
| */ | |
| function oneCheckboxIsCheckedInForm( form, message, matchName ) { | |
| if ( !message ) { | |
| message = "You must check at least one checkbox before printing"; | |
| } | |
| if ( !matchName ) { | |
| matchName = "."; | |
| } | |
| // loop through all the elements in the form | |
| for (var i = 0; i < form.elements.length; i++) { | |
| // If the element is a checkbox | |
| if (form.elements[i].type == "checkbox" && form.elements[i].name.match( matchName ) ) { | |
| // If the checkbox is checked | |
| if (form.elements[i].checked) { | |
| return true; | |
| } | |
| } | |
| } | |
| // else | |
| alert(message); | |
| return false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment