Check All/Clear All links for dynamic check-boxes
In forms when using check boxes for a list of records that is generated dynamically (example: display of messages in your yahoo or hotmail inbox) you might want a simple feature of checking or clearing all the check boxes related to those records before deleting or moving. Use this simple script to do just so.
Example of Check All/ Clear All links for dynamically created check boxes
Cut and Paste Code
Cut 'n' paste code for the above Example
- Function SetChecked is used
to check and clear the check boxes : Here we find all elements
in the form which are check boxes with a given name (this name
is sent through the link, so you can have more then one check/clear
If the boxes need to be checked the property 'checked' of the elements is set to 1 and 0 if they are to be cleared. To do this we send the value 1 or 0 through the link.
- Function ValidateForm is used to validate the form to see if at least one check box is ticked on submission : Here we check all the check boxes with the given name to see if at least one is checked. If one is found then we return true to the form submission else we return false and an alert message.