function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
shinerajbshinerajb 

Issue with javascript

Hai,

 

I have an issue with my javascript for treeview.The issue is that while I am selecting a single parent checkbox,then the entire child checkboxes of every parent node is also get checked.What is the issue with my javascript?

 

***script***

 

function checkAll(cb,cbid)
{

var inputElem = document.getElementsByTagName("input");

for(var i=0; i<inputElem.length; i++)
{
if(inputElem[i].id.indexOf(cbid) !=-1)
{
if(cb.checked)
{
inputElem[i].checked = true;

}
else
{
inputElem[i].checked = false;

}
}
}

}

 

*****VF page*****

 

<ul id="tree1" class="filetree">
<apex:repeat value="{!AllIndustries}" var="parent">
<li><span class="folder"><strong><input type="checkbox" id="checkInd1" name="{!parent.industries_level1_id}" value="{!parent.industries_level1_id}" onclick="checkAll(this,'checkInd2')"/>
<apex:outputtext style="color:blue;" escape="false" value="{!parent.industries_level1_name}"/></strong></span>
<ul>
<apex:repeat value="{!parent.industries_level2}" var="child">
<li><span class="folder">
<input type="checkbox" id="checkInd2" value="{!child.industries_level2_id}" />
<apex:outputtext style="color:green;" escape="false" value="{!child.industries_level2_name}"/></span>

</li>
</apex:repeat>
</ul>

</li>
</apex:repeat>
</ul>

TarentTarent

At my system your code is running good

Dev-FoxDev-Fox
Hi Shinerajb,
This could be due to cache. You can simply delete your browser cache or follow 2 changes as sown below
add name attribute like: <input type="checkbox" id="checkInd2" name="{!parent.industries_level1_id}" value="{!child.Name}" /> and 
change js condition to if(inputElem[i].id.indexOf(cbid) !=-1 && inputElem[i].name == cb.name)