Forum Moderators: open
I am trying to figure out how to deselect the first 50 (or whatever number) of checkboxes on a webpage. There can be up to 500 checkboxes on any given page. If the function has already been applied to the first 50 checkboxes, then it should work on the next 50 if selected again.
Any idea on how I should approach this task?
Thanks for your help!
function setCheckedState (form) {
if (!form) {
form = document;
}
if (!form.getElementsByTagName) {
form.getElementsByTagName = function(tagName) {
return getElementsByTagName(this, tagName);
}
}
var next = 0;
var inputs = form.getElementsByTagName('input');
for (i = 0; i < 50; ++i)
{
while (1)
{
if (inputs[i + next].type.toLowerCase() == 'checkbox')
{
if (inputs[i + next].checked == true)
{ inputs[i + next].checked = false;
break; }
else next++;
}
else next++;
if ((i + next) == inputs.length) return;
}
}
}
}function uncheckfirst50(form) {
setCheckedState(form);
}
Hope this works.
Credits go to kanenas at [htmlcodetutorial.com...]
Best regards!
Michal Cibor