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

Selecting all checkboxes between a DIV tag

Status
Not open for further replies.

Mayoor

Programmer
Jan 16, 2004
198
GB
Hi I have a form which has about 50 check boxes. However some of those checkboxes are between a divtag of id=childrensgroup.

Is there any way in Javascript that I can click a checkbox called "Select all checkboxes in the childrens group" outside the DIV tag which will then select all the checkboxes between the div tag with id=childrensgroup.

Thanks for any help.
 
Dan - No your code didnt work because of the nested DIVS. The code only actions the immediate checkboxes after the div and doesnt action anything in the nested divs.

vbkris - I am just trying out your Idea. I am setting the id of the checkbox to the value of the db identity and then adding a "3" at the end. I will then test the last character of the id of the checkbox to see if it is a 3 and if it is CHECK it!

 
Oh dear.. My apologies. I have just realised the first line of the code snippet I gave was totally wrong. If you change this:

Code:
var cbs = document.getElementById('childrensgroup');

to this:

Code:
var cbs = document.getElementById('childrensgroup').getElementsByTagName('input');

all should be well.

Hope this helps,
Dan


[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
here is the code that made it work in the end

Code:
function CheckAll(TheName,TheType)
{
	var idName;
	
	TheElem=document.forms[1].elements
	for(i=0;i<TheElem.length;i++)
	{
		idName = TheElem[i].id
		idNameFormatted = idName.charAt(2)											
		if(idNameFormatted==3)
		{
			if(TheElem[i].checked == true)
			{
				TheElem[i].checked = false;
			}
			else
			{
				TheElem[i].checked = true;
			}
		}
	}
}


HTML

Code:
<%
intRecordNumber = 0							
if not Interest3RS.EOF then
	while not Interest3RS.eof
	
%>
<div class="rSBTT"><div class="rSKNSLC"><label for="05yes"><%=Interest3RS("Title")%></label></div>
	<div class="rSNSRC"><input type="checkbox" name="interest" value="<%=Interest3RS("InterestID")%>" ID="<%=intRecordNumber%>_<%=Interest3RS("InterestTypeID")%>"/>
		</div>
	<div class="cF">&nbsp;Yes </div>
</div>
<div class="sV9"></div>
<%							
	Interest3RS.MoveNext
	intRecordNumber = intRecordNumber + 1
	wend
End If													
%>
 
Billy - thanks for that will bear that in mind, would liked to have tried it your way in the end as it looks a lot slicker!

 
Im getting hammered by my boss for spending so much time on such a small piece of functionality, will put yours in place later!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top