toggle checkboxes javascript using prototype
Toggle All Check Boxes using prototype javascript library.
function toggleCheckBoxes(formName) {
// toggle Check Boxes using Prototype Library
var form=$(formName);
var i=form.getElements('checkbox');
i.each(function(item)
{
if (item.checked){
item.checked=false;
}
else {
item.checked=true;
}
}
);
}
to call use no quotes around the form name:
onClick="toggleCheckBoxes(formName);"
Another example using some prototype shorthand to enable and disable a single checkbox:
for this input checkbox element:
< input id="EXCESS_AMT0" name="isNotUsed" type="checkbox" >
which has the id=”EXCESS_AMT0″
we can manipulate this input field like this:
// Enable checkbox
Field.enable('EXCESS_AMT0');
// uncheck that box
$('EXCESS_AMT0').checked = false;
// Disable checkbox
Field.disable('EXCESS_AMT0');
// Check that box
$('EXCESS_AMT0').checked = true;
If you find this post helpful, please click an ad below. Thanks!
4 Comments »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Powered by WordPress
RSS Feed - Syndicate this Site
and comments feed




Comment by rc — 24-Oct-2009 #
Short and sweet. Thnx!
Comment by Andres Canavesi — 3-Nov-2009 #
I didn’t know Field.disable, thanks :)
Comment by Nick — 11-Nov-2009 #
Wow, first try thanks!
Comment by Nick — 11-Nov-2009 #
When using a checkbox to trigger the check/uncheck event, remember to assign it an id and create an exception inside the function within toggleCheckBoxes (like if(item.id == ‘toggle_checkbox’) return; ) or else that checkbox will never change its checked status.