Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Selecting multiple checkboxes with a single checkbox.

Reply
Thread Tools

Selecting multiple checkboxes with a single checkbox.

 
 
Eric
Guest
Posts: n/a
 
      10-23-2003
Hi all,

I have a form that generates a dynamic number of rows from a value
passed in via querystring. I have a one static row in my form with a
"master" checkbox that I have deemed "Select All:". I want to be able
to select all and deselect all the other checkboxes beneath it in the
column by clicking on it. I've gotten it partially working. I can
click the "master" checkbox and it will set the .checked property of
all the others to true. BUT how do I reverse the process and turn them
all off? Here is my funcion:

function selectAllInstall()
{
var frm;
frm = document.frm;

if (frm.chkCheckAllInstall.checked = true)
{
for (var i = 0; i < <%=dtlQty%>; i++)
{
frm.chkInstallReq[i].checked = true;
}
}

if (frm.chkCheckAllInstall.checked = false)
{
for (var i = 0; i < <%=dtlQty%>; i++)
{
frm.chkInstallReq[i].checked = false;
}
}
}

HTML for the Main Checkbox:
<td class="mnuHdr"><input type="checkbox" name="chkCheckAllInstall"
onClick="selectAllInstall();"></td>

Any ideas or suggestions would be greatly appreciated.

Thanks.
 
Reply With Quote
 
 
 
 
Oz
Guest
Posts: n/a
 
      10-24-2003
Here is a simple solution:

<script language="javascript">
function checkAll(master){
var checked = master.checked;
var col = document.getElementsByTagName("INPUT");
for (var i=0;i<col.length;i++) {
col[i].checked= checked;
}
}
</script>

Master: <input type="checkbox" onclick="checkAll(this)"><br>
Slave1:<input type="checkbox" ><br>
Slave2:<input type="checkbox" ><br>

regards
Mike




"Eric" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi all,
>
> I have a form that generates a dynamic number of rows from a value
> passed in via querystring. I have a one static row in my form with a
> "master" checkbox that I have deemed "Select All:". I want to be able
> to select all and deselect all the other checkboxes beneath it in the
> column by clicking on it. I've gotten it partially working. I can
> click the "master" checkbox and it will set the .checked property of
> all the others to true. BUT how do I reverse the process and turn them
> all off? Here is my funcion:
>
> function selectAllInstall()
> {
> var frm;
> frm = document.frm;
>
> if (frm.chkCheckAllInstall.checked = true)
> {
> for (var i = 0; i < <%=dtlQty%>; i++)
> {
> frm.chkInstallReq[i].checked = true;
> }
> }
>
> if (frm.chkCheckAllInstall.checked = false)
> {
> for (var i = 0; i < <%=dtlQty%>; i++)
> {
> frm.chkInstallReq[i].checked = false;
> }
> }
> }
>
> HTML for the Main Checkbox:
> <td class="mnuHdr"><input type="checkbox" name="chkCheckAllInstall"
> onClick="selectAllInstall();"></td>
>
> Any ideas or suggestions would be greatly appreciated.
>
> Thanks.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting multiple checkboxes inside a GridView control Mark B ASP .Net 3 03-30-2009 01:19 AM
Re: Selecting multiple fields, out of order, in a single Java XPathexpression Martin Honnen XML 0 07-18-2008 04:11 PM
Help selecting multiple checkboxes based on partial value JL Javascript 7 03-10-2008 01:10 AM
Selecting multiple CheckBoxes in a CheckBoxList Rick C ASP .Net Web Controls 0 06-29-2004 01:44 PM
Selecting/deselecting checkboxes Jez Javascript 4 07-18-2003 10:19 AM



Advertisments