You need to sign in to do that
Don't have an account?
Prabha
seems simple, but not working, An issue with javascript and pageblocktable
Hi,
I am trying to populate value in one field based on the picklist selection in different field of the samae object.
exactly like "stage" and "probability" in opportunity..
please check the code and tell me why it is not working only in apex:pageBlockTable.
I searched the boards and followed some solution but its not coming,
my VF is:
<apex:page standardController="contact" extensions="practice4"> <script type="text/javascript"> function populatefield() { var ex = document.getElementById('{!$Component.form.block.sec.firstfieldID}').value; if(ex=="one") document.getElementById('{!$Component.form.block.sec.secondfieldID}').value = '1'; else document.getElementById('{!$Component.form.block.sec.secondfieldID}').value = ''; var ex = document.getElementById('{!$Component.form.block.sec.table.firstfieldID1}').value; alert(ex); if(ex=="one") document.getElementById('{!$Component.form.block.sec.table.secondfieldID1}').value = '1'; } </script> <apex:form id="form" > <apex:pageBlock id="block" > <apex:pageBlockSection id="sec" > <apex:inputField id="firstfieldID" value="{!contact.third__c}" onchange="populatefield();" /> <apex:inputField value="{!contact.second__c}" id="secondfieldID" /> <apex:pageBlockTable id="table" value="{!section1}" var="allGNG"> <apex:column headervalue="pick" width="15%" > <apex:inputField id="firstfieldID1" value="{!allGNG.third__c}" onchange="populatefield();" > </apex:inputField> </apex:column> <apex:column headerValue="value"> <apex:inputField value="{!allGNG.second__c}" id="secondfieldID1" /> </apex:column> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
my controller is
public class practice4 { public practice4(ApexPages.StandardController controller) { } public contact[] section1 = new contact[0]; Public List<contact> getsection1() { section1= [SELECT third__c, second__c from contact]; return section1; } }
what I saw is "document.getElementById" is getting the values from pageblocksection, but not from pageblocktable.
Is there any other way...?!?
Thanks
Prabhan
I think a better solution would be to pass "this" in populateField function.
onchange="populatefield(this)"
Try this out. hope this helps :D
All Answers
After your page has loaded, view the source and can you post the converted javascript/html code here?
from IE...
Thanks
Prabha
Can you compare with the generated HTML of the pageblock/table and see if the ids are correct?
wow, thats great guys,
now I understand the reason why it is not pulling it... there is this identifier for each record.
please see
Its always wrong with the '0'.
now the question is, how to deal with it. please throw some light.
thanks
prabha.
I think a better solution would be to pass "this" in populateField function.
onchange="populatefield(this)"
Try this out. hope this helps :D
way to use javascript.
it worked.
thanks :)