Possible to check a range of checkboxes with one click?

F

Fred

If I have a list of check boxes on a web form, is there a method to select a few
rows (e.g. shift-click or ctrl-click )at one time without checking them all?
Thanks in advance.



Fred
 
A

ASM

Fred a écrit :
If I have a list of check boxes on a web form, is there a method to select a few
rows (e.g. shift-click or ctrl-click )at one time without checking them all?
Thanks in advance.

you can add a checkbox to check all together

<p>
check/uncheck all : <input type=checkbox
onclick="var C = parentNode.getElementsByTagName('INPUT');
for(var i=0;i<C.length; i++) C.checked = this.checked;">
item 1 <input type=checkbox name="choice_1">
item 2 <input type=checkbox name="choice_2">
item 3 <input type=checkbox name="choice_3">
</p>
 
F

Fred

If I have a list of check boxes on a web form, is there a method to select a few
rows (e.g. shift-click or ctrl-click )at one time without checking them all?
Thanks in advance.

you can add a checkbox to check all together

<p>
check/uncheck all : <input type=checkbox
onclick="var C = parentNode.getElementsByTagName('INPUT');
for(var i=0;i<C.length; i++) C.checked = this.checked;">
item 1 <input type=checkbox name="choice_1">
item 2 <input type=checkbox name="choice_2">
item 3 <input type=checkbox name="choice_3">
</p>
[/QUOTE]

Thanks for the reply. I was trying to find a way to select a block of them at
one time, without selecting them all. As an example if I had 150 items lists,
and only wanted to check 35 of them, would there be a way to use a shift-click
or ctrl-click to just pick that block at one time.

Fred
 
E

Evertjan.

Fred wrote on 13 dec 2006 in comp.lang.javascript:
Thanks for the reply. I was trying to find a way to select a block of
them at one time, without selecting them all. As an example if I had
150 items lists, and only wanted to check 35 of them, would there be a
way to use a shift-click or ctrl-click to just pick that block at one
time.

If you are content with just clicking start and end radiobuttons,
try this:

============= test.html ===================

<script type='text/javascript'>
function slk(){
var start = document.forms[0].start;
for (i=0;i<start.length;i++)
if (start.checked)
startN = i+1;
var end = document.forms[0].end;
for (i=0;i<end.length;i++)
if (end.checked)
endN = i+1;
if (startN>endN) {
var temp = startN;
startN = endN;
endN = temp;
}
for (i=1;i<=start.length;i++)
document.forms[0].elements['c'+i].checked =
(i>=startN && i<=endN)
}
</script>


<form>
item 1: <input type=checkbox name='c1'>
start: <input type=radio name='start' onclick='slk()' checked>
end: <input type=radio name='end' onclick='slk()'><br>

item 2: <input type=checkbox name='c2'>
start: <input type=radio name='start' onclick='slk()' >
end: <input type=radio name='end' onclick='slk()'><br>

item 3: <input type=checkbox name='c3'>
start: <input type=radio name='start' onclick='slk()'>
end: <input type=radio name='end' onclick='slk()'><br>

item 4: <input type=checkbox name='c4'>
start: <input type=radio name='start' onclick='slk()'>
end: <input type=radio name='end' onclick='slk()'><br>

item 5: <input type=checkbox name='c5'>
start: <input type=radio name='start' onclick='slk()'>
end: <input type=radio name='end' onclick='slk()' checked><br>
</form>

=====================================
 
A

ASM

Fred a écrit :
Thanks for the reply. I was trying to find a way to select a block of them at
one time, without selecting them all. As an example if I had 150 items lists,
and only wanted to check 35 of them,

I think easiest way is toy put these 35 elements in a container to
accede them.
would there be a way to use a shift-click
or ctrl-click to just pick that block at one time.

I do not understand why you prefer a keys combination to a simple button?

function checkAll(what, me) {
what = document.getElementById(what).getElementsByTagName('INPUT');
for(var i=0;i<what.length; i++)
if(what.type=='checkbox') what.checked = me.checked;
}


<p>Check/uncheck all group 2 :
<input type="checkbox" onclick="checkAll('group_2', this)">
<p>Check/uncheck all group 3 :
<input type="checkbox" onclick="checkAll('group_3', this)">
blah blah
<p id="group_2">
item 1 <input type=checkbox name="choice_1">
item 2 <input type=checkbox name="choice_2">
item 3 <input type=checkbox name="choice_3">
</p>
blah
blah
<p id="group_3">
item 31 <input type=checkbox name="choice_31">
item 32 <input type=checkbox name="choice_32">
item 33 <input type=checkbox name="choice_33">
</p>


You can also use :


function checkAll(what, ok) {
what = what.getElementsByTagName('INPUT');
for(var i=0;i<what.length; i++)
if(what.type=='checkbox') what.checked = ok;
}

<fieldset ondblclick="this.val= !this.val; checkAll(this, this.val);">
double click = check/uncheck all this block<br>
item 31 <input type=checkbox name="choice_31">
item 32 <input type=checkbox name="choice_32">
item 33 <input type=checkbox name="choice_33">
</fieldset>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top