Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If first checkbox checked, check all 1

Status
Not open for further replies.

SoonerNation

Programmer
Dec 7, 2005
12
US
I tried the solution offered in archived thread thread216-881568 but it doesn't seem to work for me.

Like the original poster, I have a master checkbox and need all other checkboxes in the form to set to the same value as the master, no matter their current value.

Any help is very much appreciated.
Lyndon

I copied the following script exactly:

<script type="text/javascript">
function checkAll(el) {
var isChecked = el.checked;
var form = el.form;
var els = form.elements;

for (var x = 0; x < els.length; x++) {
if (el != els[x]
&& els[x].type
&& els[x].type.toLowerCase() == "checkbox") {
// set to same state as master checkbox
els[x].checked = isChecked;

if (isChecked) {
// keep checked
els[x].onclick = function(){this.checked = true;}
}
else {
// normal behavior
els[x].onclick = null;
}
}
}
}
</script>
and used it in this context:

<form name="EMailList" action="EMailChecked.cfm" method="POST">
<tr>
<td class="ColumnHeadingCell" colspan="4">
<div align="Left"><input type="Checkbox" name="Master" onclick="checkall(this);">&nbsp;All</div>
<div align="center">
<input type="submit" name="B1" value="EMail Checked">
<input type="reset" name="B2" value="Clear Checks">
</div>
</td>
</tr>
<tr>
<td class="ColumnHeadingCell">
&nbsp;
</td>
<td class="ColumnHeadingCell">
<a href="email.cfm?mOrder=Name" class="InColumnHeader">Sort by Name</a>
</td>
<td class="ColumnHeadingCell">
<a href="email.cfm?mOrder=Department" class="InColumnHeader">Sort by Department</a>
</td>
<td class="ColumnHeadingCell">
<a href="email.cfm?mOrder=Location" class="InColumnHeader">Sort by Location</a>
</td>
</tr>
<cfoutput query="BinkleyUser">
<tr>
<td class="NormalCell">
<input type="Checkbox" name=#Trim(BinkleyUser.UserLogin)#>&nbsp;
</td>
<td class="NormalCell">
<cfset mName='Send email to '&Trim(BinkleyUser.FirstName)&' '&Trim(BinkleyUser.LastName)>
<a href="mailto:#BinkleyUser.EMail#" class="Special" title="#mName#">#UCase(BinkleyUser.FirstName)# #UCase(BinkleyUser.LastName)#</a>
</td>
<td class="NormalCell">
#UCase(BinkleyUser.Office)#
</td>
<td class="NormalCell">
#UCase(BinkleyUser.Location)#
</td>
</tr>
</cfoutput>
</form>
 
try checkAll, not checkall...

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top