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

Selecting multiple Dynamically name checkboxes- Please Help

Status
Not open for further replies.

ssepai

Programmer
Feb 19, 2008
3
US
Hello All,

I have a CF template wherein I have a list of checkboxes. The parent Checkboxe is the department and below that is the list of employees. If the user selects the parent checkbox then all the checkboxes below it should get selected. It is not giving me any error but the length of the employee checkboxes is coming up as zero. I checked all the boxes have the same name.

The Coldfusion code:
<tr><td>
<strong>#Department#</strong>
<input type="checkbox" id="#DepartmentID##PermID#" style="cursor:pointer" onclick="SelectAll(this.id)">
<table id="DeptRow#ctr##PermID#" style="display:none;">
<cfloop query="GetEmployees">
<tr>
<td>#GetEmployees.Firstname#
<input type="checkbox" id="Chk#DepartmentID##PermID#" name="Chk#DepartmentID##PermID#" style="cursor:pointer">Chk#DepartmentID##PermID#</td>
</tr>
</cfloop>

THE JAVASCRIPT CODE:

function SelectAll(DeptID){
var chkbox = "Chk" + DeptID;
var cboxes = document.all.frmAddEdit.getElementsByTagName(chkbox);
if (typeof(cboxes) != 'undefined'){
for (i = 0; i < cboxes.length; i++)
cboxes.checked = true ;
}

}

Thanks for the help in advance.
 
We would ask you post the resultant HTML after the Coldfusion has been parsed as that is what the Jacvascript sees, and uses.

First: You are attempting to use document.all which is not only deprecated and should be avoided, its basically an IE only element. Which means no other browser will support it.


Second: Unless you have checkboxes outside your frmAddEdit form you can skip the dom tree, and use the getElementsByTagName function directly form the document object.

Third and most importantly, the getElementsByTagName returns an array of elements of a specific type: checkboxes, divs, spans, images etc.. It does not return an array of checkboxes by their name attribute. For that you should be using getElementsBy[red]Name[/red].

One or all of these could be the cause of your issues.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Thank you very much. I was able to resolve the issue and thank you for the tips too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top