You need to sign in to do that
Don't have an account?

Use javascript in <apex:repeat>
Hi all .
I've used <apex:repeat> and following structure is iterated :
Please provide the the model of printer field and Please specify field
In below image when i select Other for 'Please provide the model of printer' only i should display please specific Text box.
But since this block created dynamically i can not use javascript. How can i handle this situation??
note that i've used pageblocksection between please specific Text box.

Please help me.
I've used <apex:repeat> and following structure is iterated :
Please provide the the model of printer field and Please specify field
In below image when i select Other for 'Please provide the model of printer' only i should display please specific Text box.
But since this block created dynamically i can not use javascript. How can i handle this situation??
note that i've used pageblocksection between please specific Text box.

Please help me.
All Answers
var value=obj.value;
var repeatId=0;
hideArea='mainPage:mainForm:pageBlock3:pageBlockSection5:scanner1Section:scannerList:'+repeatId+':scannerPageBlockSection:scannerModelsOther';
if(value=='Other'){
document.getElementById(hideArea).stlye.display='block';
}
else{
document.getElementById(hideArea).stlye.display='none';
}
}
This is the function i used, for var repeateid i can extract the value from current field and assign to hideara.. Before extract the valuei just hardcoded 0 (which is existing)
But we can not hide an area in this way..
Please help me
One thing to note is that, if you are using <apex> tags, you need to use the {!$Component} global merge field to reference an element's ID. If your markup looks like this
<apex:outputPanel id="panel">
<apex:outputText id="text">Some text</apex:outputText>
</apex:outputPanel>
Then you would reference the apex:outputText element in javascript like this
document.getElementById("{!$Component.panel.text}");
There are several pageblocks and i have this code in a middle of such a pageBlock.
please help me Thanks a lot
<div id="scannersDiv">
<apex:variable value="2" var="num"/>
<apex:repeat value="{!Scanner_List}" var="scanner" id="scannerList">
<apex:pageBlockSection id="scannerPageBlockSection" title="Scanner {!num}" columns="1" collapsible="false">
<apex:variable var="num" value="{!VALUE(num) + 1}"/>
<apex:inputField id="scannerModel" onclick="changeScannersModel(this)" value="{!scanner.Model_of_Scanner__c}" label="Please provide the model of scanner:"/>
<apex:pageblockSection id="scannerModelsOther">
<apex:inputField value="{!scanner.Specify_Model__c}" label="Please Specify:"/>
</apex:pageblockSection>
</apex:pageBlockSection>
</apex:repeat>
</div>
Next, I would try adding an ID attribute to the Specify Model inputField, so that your javascript can get at it: <apex:inputField id="{!scanner.Id}".../>. Then, your javascript can look something like this
function changeScannersModel(obj){
var scannerId = obj.getAttribute("scannerId");
var scannerModel=obj.value;
var repeatId=0;
hideArea='{!$Component.mainPage.mainForm.pageBlock3.pageBlockSection5.scanner1Section.scannerList.scannerPageBlockSection-'+scannerId+'.'+scannerId;
if(scannerModel=='Other'){
document.getElementById(hideArea).style.display='block';
}
else{
document.getElementById(hideArea).style.display='none';
}
}
Putting your Visualforce together, you'll have something like this
<div id="scannersDiv">
<apex:repeat value="{!Scanner_List}" var="scanner" id="scannerList">
<apex:pageBlockSection id="scannerPageBlockSection-{!scanner.Id}" title="Scanner {!num}" columns="1" collapsible="false">
<apex:inputField styleClass="scannerModel" html-scannerId="{!scanner.Id}" onclick="changeScannersModel(this)" value="{!scanner.Model_of_Scanner__c}" label="Please provide the model of scanner:"/>
<apex:pageblockSection id="scannerModelsOther-{!scanner.Id}">
<apex:inputField id="{!scanner.Id}" value="{!scanner.Specify_Model__c}" label="Please Specify:"/>
</apex:pageblockSection>
</apex:pageBlockSection>
</apex:repeat>
</div>
Error: Literal value is required for attribute id in <apex:pageblockSection>
if(scannerModel=='Other'){
this.nextSibling.style.display='block';
}
else{
this.nextSibling.style.display='none';
}
But i can not hide the sectionwith that logic.
Thathula
function changeScannersModel(obj){
var value=obj.value;
var repeatId=0;
hideArea='mainPage:mainForm:pageBlock3:pageBlockSection5:scanner1Section:scannerList:'+repeatId+':scannerPageBlockSection:scannerModelsOther';
if(value=='Other'){
document.getElementById(hideArea).stlye.display='block';
}
else{
document.getElementById(hideArea).stlye.display='none';
}
}
Have i done any wrong somewhere???