You need to sign in to do that
Don't have an account?
Rick MacGuigan
Using javascript and $Component
I can't seem to get a handle on a input field from my javascript function 'checkNumbers.' The initial alert pops up with the onChange event. The second alert pops up but with no value. The field is a percent type so the String() function is used. However, I think the issue is with traversing the objects using $Component. Below is my VF code. Am I traversing this object correctly ?
<apex:page id="page" standardController="Comm_Auto_Audit_Sample_Policy__c" extensions="AuditCommAutoPolicySampleController" > <script type="text/javascript"> function closepage() { top.window.close(); } </script> <script> function checkNumbers() { alert('Debug 1'); var x = document.getElementById("{!$Component.page.form1.block1.ajaxrequest2.section2.value2}").innerHTML; alert(String(x)); } </script> <!-- ********************************************** --> <!--Establish control variables The control variables are used to streamline naming conventions and ease rendering references. //--> <!--Set Object reference variable --> <!-- declare variable for dependency to field in new controller. --> <apex:variable var="AuditID" value="{!Comm_Auto_Audit_Sample_Policy__c.Audit__c}" /> <apex:variable var="sample" value="{!Comm_Auto_Audit_Sample_Policy__c}" /> <!--Contoller Information variables --> <apex:variable var="a" value="{!Audit}" /> <!-- ********************************************** --> <apex:form id="form1"> <apex:pageBlock id="block1" title="Commercial Auto Audit Sample Data (Policy: {!Comm_Auto_Audit_Sample_Policy__c.Policy_Number__c})" > <!-- ********************************************** --> <apex:pageBlockButtons location="top"> <apex:commandButton value="Save" action="{!Save}"/> <apex:commandButton value="Save and Return to Template" action="{!saveAndReturn}"/> </apex:pageBlockButtons> <!--Debug info for state changes set rendered="true" to enable section --> <apex:pageBlockSection columns="1" id="testsection1" title="TEST & Debug Section" rendered="false" > <!-- ....Parent ID Number is : "{!ParentID}"<br></br> ....Personal Auto Product is : "{!PersonalAutoProduct}"<br></br> ....Personal Parent Audit Name is : "{!AuditName}"<br></br> //--> </apex:pageBlockSection> <script>twistSection(document.getElementById("{!$Component.testsection1}").childNodes[0].childNodes[0]); </script> <!-- ************************************************************************************************ --> <apex:outputPanel id="ajaxrequest2"> <apex:pageBlockSection columns="1" id="section2" title="Operations" rendered="{!Operations}" > <apex:inputField value="{!Comm_Auto_Audit_Sample_Policy__c.Type_of_Operations__c}" id="operation" rendered="{!TypeOfOperations}" > <apex:actionSupport event="onchange" reRender="section2" /> </apex:inputField> <apex:inputField value="{!Comm_Auto_Audit_Sample_Policy__c.Radius_of_Operations__c}" rendered="{!RadiusOfOperations}" > <apex:actionSupport event="onchange" reRender="section2" /> </apex:inputField> <apex:inputField value="{!Comm_Auto_Audit_Sample_Policy__c.Percent_Local__c}" style="color:blue;" rendered="{!CONTAINS(Comm_Auto_Audit_Sample_Policy__c.Radius_of_Operations__c,'Local') && (RadiusOfOperations)}" /> <apex:inputField value="{!Comm_Auto_Audit_Sample_Policy__c.Percent_Intermediate__c}" style="color:blue;" id="value2" onchange="checkNumbers();" rendered="{!CONTAINS(Comm_Auto_Audit_Sample_Policy__c.Radius_of_Operations__c,'Intermediate') && (RadiusOfOperations)}" /> <apex:inputField value="{!Comm_Auto_Audit_Sample_Policy__c.Percent_Long_Haul__c}" style="color:blue;" id="value1" onchange="checkNumbers();" rendered="{!CONTAINS(Comm_Auto_Audit_Sample_Policy__c.Radius_of_Operations__c,'Long-Haul') && (RadiusOfOperations)}" > <apex:actionSupport event="onchange" reRender="longhaul" /> </apex:inputField> </apex:pageBlockSection> </apex:outputPanel> </apex:pageBlock> </apex:form> </apex:page>
All Answers
You may find this useful:
Here is the controller;
Thanks again for all your help !
Here is the solution using jQuery. I took the liberty to optimize and compress the code as well, It is assumed that all id attribute values are unique throughout the page.