You need to sign in to do that
Don't have an account?
Gunnam Ram
Javascript not calling for Onchange Event
Hi, Below is the code I have written to call Controller method from Javascript. But the issue I have identified is Onchange is not calling javascript . tried all possible ways. Please let me know where issue persists in below code.
<apex:page standardController="Address1__c" extensions="Address1controller">
<script type="text/javascript">
function setRequired(countryvar) {
var country = document.getElementByID(countryvar);
reRenderBlock(country);
}
</script>
<apex:form id="theForm">
<apex:actionFunction name="reRenderBlock" action="{!setzipcoderequired}">
<apex:param id="country" name="country" value="" />
</apex:actionFunction>
<apex:pageBlock id="thePageBlock">
<apex:pageBlockSection id="thePageBlockSection">
<apex:inputField id="country" value="{!Address1__c.Billing_Country__c}" onchange="setRequired({!$Component.country});"/>
<apex:inputField id="zipcode" value="{!Address1__c.Billing_Zip__c}" required="{!check}"/>
<apex:commandButton action="{!Save}" value="Save"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
<apex:page standardController="Address1__c" extensions="Address1controller">
<script type="text/javascript">
function setRequired(countryvar) {
var country = document.getElementByID(countryvar);
reRenderBlock(country);
}
</script>
<apex:form id="theForm">
<apex:actionFunction name="reRenderBlock" action="{!setzipcoderequired}">
<apex:param id="country" name="country" value="" />
</apex:actionFunction>
<apex:pageBlock id="thePageBlock">
<apex:pageBlockSection id="thePageBlockSection">
<apex:inputField id="country" value="{!Address1__c.Billing_Country__c}" onchange="setRequired({!$Component.country});"/>
<apex:inputField id="zipcode" value="{!Address1__c.Billing_Zip__c}" required="{!check}"/>
<apex:commandButton action="{!Save}" value="Save"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Did you check the javascript console in your browser? Sounds like you might be getting a JS error that's preventing the method from executing. In fact, it looks like you might need to add quotes around Component.country in your call to the setRequired method. Try changing
To
All Answers
Did you check the javascript console in your browser? Sounds like you might be getting a JS error that's preventing the method from executing. In fact, it looks like you might need to add quotes around Component.country in your call to the setRequired method. Try changing
To