Selecting multiple checkboxes with a single checkbox.

E

Eric

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.checked = true;
}
}

if (frm.chkCheckAllInstall.checked = false)
{
for (var i = 0; i < <%=dtlQty%>; i++)
{
frm.chkInstallReq.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.
 
O

Oz

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.checked= checked;
}
}
</script>

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

regards
Mike
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top