<apex:form id="formId">
<script>
function HideMsg(istrue)
{
var checkval = document.getElementById("msg")
if(istrue.checked)
{
var checkval = document.getElementById("msg").style.display='block';
}
else
{
var checkval = document.getElementById("msg").style.display='none';
}
}
</script>
<apex:pagemessages />
<apex:pageBlock id="pageblockId">
<apex:pageBlockSection Id="pageblocksectionId">
<apex:inputFile value="{!csvFileBody}" filename="{!csvAsString}"/>
<apex:commandButton value="Import Project" action="{!importCSVFile}"/>
</apex:pageBlockSection>
<apex:pageBlock >
<apex:pageBlockSection title="Project List" columns="1" >
<apex:pageBlockTable value="{!Project2}" var="a" border="1">
<apex:column value="{!a.Name}"/>
<apex:column >
<!--<apex:pageBlockTable value="{!a.Project_Tasks__r}" var="c">
<apex:column value="{!c.Name}"/>
</apex:pageBlockTable>-->
<div>
<apex:inputCheckbox id="checkbox" onchange="HideMsg(this); "/>
</div>
<div class="showp" style="display: none" id="msg">
<apex:repeat value="{!a.Project_Tasks__r}" var="c">
<apex:outputText value="{!c.Name}">
</apex:outputText>
</apex:repeat>
</div>
</apex:column>
<apex:column value="{!a.Developer_Name__c}"/>
<apex:column value="{!a.Client_Name__c}"/>
<apex:column value="{!a.Date__c}"/>
<apex:column value="{!a.Start_Date__c}"/>
<apex:column value="{!a.End_Date__c}"/>
<apex:column value="{!a.Error_at_Project__c}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:pageBlock>
</apex:form>
-
Welcome to SFSE! Please take the tour and read How to Ask. Right now, the problem you're having isn't clear. I've fixed the formatting of your code and VF page so that it is all rendered by the site (stackexchange purposefully doesn't render a lot of things that look like HTML for security reasons). A single statement and a code dump is usually not enough to identify an issue. You should edit your question to include more details.– Derek FCommented Feb 10, 2020 at 12:15
-
So, I have vf page as per above code and have two object 1) Project(parent) 2) project task (child) . when I select the check as true it only show related project task which I had select the project. it only showing the first project task when I mark as true– Bhargav vaishnavCommented Feb 10, 2020 at 13:48
Add a comment
|
1 Answer
You need to assign a particular id on show/hide section and pass the same id reference on some attribute of checkbox so that system show/hide section.
here is example
<apex:page controller="testController">
<apex:form id="formId">
<script>
function HideMsg(checkbox)
{
console.log(checkbox.title);
var title = checkbox.title;
if(checkbox.checked)
{
var checkval = document.getElementById(title).style.display='block';
}
else
{
var checkval = document.getElementById(title).style.display='none';
}
}
</script>
<apex:pagemessages />
<apex:pageBlock id="pageblockId">
<apex:pageBlockSection Id="pageblocksectionId">
</apex:pageBlockSection>
<apex:pageBlock >
<apex:pageBlockSection title="Project List" columns="1" >
<apex:pageBlockTable value="{!Project2}" var="a" border="1">
<apex:column value="{!a.Name}"/>
<apex:column >
<!--<apex:pageBlockTable value="{!a.Project_Tasks__r}" var="c">
<apex:column value="{!c.Name}"/>
</apex:pageBlockTable>-->
<div>
<apex:inputCheckbox id="checkbox" title="{!a.Name+'-'+a.Id}" onchange="HideMsg(this); "/>
</div>
<div class="showp" style="display: none" id="{!a.Name+'-'+a.Id}">
<apex:repeat value="{!a.contacts}" var="c">
<apex:outputText value="{!c.Name}">
</apex:outputText>
</apex:repeat>
</div>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:pageBlock>
</apex:form>
</apex:page>
public class testController {
public List<Account> getProject2(){
return [Select Id,Name,(SELECT Id,Name FROM Contacts) FROM Account];
}
}