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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to check one checkbox to select all checkboxes in list 1

Status
Not open for further replies.

ashw

MIS
Jun 10, 2002
61
CA
I have created a webpage where in order to delete from a list of weblinks on weblinks.cfm, you select its corresponding checkbox which has been dynamically added on weblinks.cfm when the weblink was created on newweblink.cfm
(by input tag written within form that submits to deleteweblink.cfm) I want to include a select all checkbox on weblinks, which when checked, checks all the weblinks for delete operaton. like in hotmail delete contacts. how do I do that?
 
Thanks, it work great when I check "select all" check box to delete but now when I uncheck it the rest of the checkbox won't be selected. How do I do that?
 
when you uncheck it, you can write a javascript function to loop through the other checkboxen and uncheck them too

sort of like the loop to check them, but this time to uncheck them

(hotmail don't work like that, does it?)

rudy
 
After writing the check function I have written uncheck function
<!--- Javascript to Uncheck all the checkboxes when Select all Check box is unchecked--->
<script language=&quot;JavaScript&quot;><!--
function UncheckAll(theForm) {
for (i=0,n=theForm.elements.length;i<n;i++)
if (theForm.elements.name.indexOf('dID') !=-1)
theForm.elements.checked = false;
}
//--></script>
then at input &quot;select all&quot; check box, I have written
<input type=&quot;checkbox&quot; onClick=&quot;if (this.checked) checkAll(this.form); if (this.unchecked) UncheckAll(this.form);&quot;>


Does it make sense, it doesn't work though
 
Here is code I removed from one of my apps; I can't remember if I jacked it or not, but it works ;)

Code:
<html>
	<head>
		<title>FlipAll Test</title>
		
		<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
		function ClearAll(fElement) {
		
			for (i=0;i <= fElement.length - 1;i++) {
				
					fElement[i].checked=0;
			}
			
		}

		function CheckAll(fElement) {
		
			for (i=0;i <= fElement.length - 1;i++) {
				
					fElement[i].checked=1;
			}
			
		}		
		</script>
		
	</head>
	
<body>

<span class=&quot;FormHeadText&quot;>Checkboxes</span> - <a href=&quot;javascript:void(0);&quot; style=&quot;font-family:Verdana;font-size:12px&quot; onclick=&quot;javascript:CheckAll(document.Filter.Test);&quot;>Select All</a> | <a href=&quot;javascript:void(0);&quot; style=&quot;font-family:Verdana;font-size:12px&quot; onclick=&quot;javascript:ClearAll(document.Filter.Test);&quot;>Clear All</a><br>

<form name=&quot;Filter&quot;>

<cfoutput>
	<cfloop from=&quot;1&quot; to=&quot;10&quot; index=&quot;i&quot;>
		<input type=&quot;checkbox&quot; name=&quot;Test&quot; value=&quot;checkbox#i#&quot;> Checkbox ###i#<br>
	</cfloop>
</cfoutput>

</form>

</body>

</html>

-Tek
 
I couldn't make it work. I don't know javascript at all and can't figure out how to incorporate it with my code. I have used only one checkbox to CheckAll or UncheckAll. Whereas the weblinks' corresponding checkboxes were dynamically added when a weblink was created on a newWeblink.cfm. the coding of dynamic checkbox was done on weblinks.cfm. I have written the javascript fuctions for both CheckAll and UnCheckAll but don't know how to call them from the input Select All checkbox. Can anyone look at my code and tell me what to do, please? I will appreciate very much.

(weblinks.cfm Code)

<!---CF Includes Site Header, CSS Style Sheet and Side Menu--->
<cfinclude template=&quot;/Header.cfm&quot;>

<!--- Javascript to Check all the checkboxes when Select all check box is checked--->
<script language=&quot;JavaScript&quot;><!--
function checkAll(theForm) {
for (i=0,n=theForm.elements.length;i<n;i++)
if (theForm.elements.name.indexOf('dID') !=-1)
theForm.elements.checked = true;
}
function UncheckAll(the Form) {
for (i=0,n=theForm.elements.length;i<n;i++)
if (theForm.elements.name.indexof('dID') !=-1)
theForm.elements.checked = false;
}
//--></script>
<!---Query Weblink database--->
<CFQUERY NAME=&quot;Web&quot; DATASOURCE=&quot;weblink&quot;>
SELECT *
FROM Tblweblink
WHERE weblinkDeleteStatus = 'N'
</CFQUERY>
<body>
<!---Query Output--->
<Table>
<tr>

<TH colspan=&quot;4&quot;>
<!--- Delete a weblink when the corresponding checkbox is selected --->
<cfform action=&quot;Deleteweblink.cfm&quot; method=&quot;post&quot;>
<input type=&quot;submit&quot; name=&quot;Delete&quot; value=&quot;Delete&quot;>
<!---Goes to Trash Can ---->
&nbsp;
<input type=&quot;Button&quot; name=&quot;Trash&quot; value=&quot;Trash&quot;
onclick=&quot;window.location='Trash.cfm';&quot;>
<!--- Goes to New Weblink Page --->
&nbsp;
<input type=&quot;Button&quot; name=&quot;Create&quot; value=&quot;New Weblink&quot;
onclick=&quot;window.location='Newweblink.cfm';&quot;>
</TH>
<tr>
<TH><input type=&quot;checkbox&quot; onClick=&quot;if(this.checked) checkAll(this.form);&quot;>Select</TH>
<TH>Site</TH>
<TH>Address</TH>
<TH>Description</TH>

<cfoutput query=&quot;web&quot;>
<TR bgcolor=&quot;#IIF(CurrentRow MOD 2, DE('FFFFFF'), DE('E9E9E9'))#&quot;>
<td>
<!--- Dynamically Creates a Checkbox for Delete Operation as a new weblink is added --->
<INPUT type=&quot;checkbox&quot; name=&quot;dID&quot; value=&quot;#weblinkID#&quot;>

</td>

<td><a href=&quot;ViewEditWebLink.cfm?WeblinkID=#weblinkID#&quot;>#weblinkname#</a></td>
<td><a href=&quot;#URLDecode('#weblinkaddress#')#&quot;>#weblinkaddress#</a></td>
<TD>#weblinkDescription#</TD>
</TR>
</CFOUTPUT>
</cfform>
</TABLE>
</body>
<cfinclude template=&quot;/footer.cfm&quot;>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top