Forum Moderators: open

Message Too Old, No Replies

Need to deselect first 50 checkboxes on page

         

erikcw

8:16 pm on Jan 27, 2005 (gmt 0)

10+ Year Member



Hi all,

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!

mcibor

10:44 pm on Jan 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would make a function:

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