Problem:
If you choose SelectList Value as --none-- it needs to alert a
message to the user.
Solution:
- <apex:page controller="SelectListController">
- <script>
- function Opportunity_Validation()
- {
- var eterm=document.getElementById('{!$Component.RenewalForm:configblock:configsecblock:configexpire:expterms}').value;
- if(eterm=='0')
- {
- alert('Select Expite Term');
- }
- }
- </script>
- <apex:form id="RenewalForm">
- <apex:pageBlock id="configblock">
- <apex:pageBlockSection title="Configuration Option" columns="2" id="configsecblock">
- <apex:pageBlockSectionItem id="configexpire">
- <apex:outputLabel value="Expiry Term:" for="expireterm"/>
- <apex:selectList value="{!ExpireTerms}" multiselect="false" size="1" id="expterms" onchange="Opportunity_Validation();">
- <apex:selectOption itemValue="0" itemLabel="--none--"/>
- <apex:selectOption itemValue="1" itemLabel="1 Year"/>
- <apex:selectOption itemValue="3" itemLabel="3 Year"/>
- <apex:selectOption itemValue="5" itemLabel="5 Year"/>
- </apex:selectList>
- </apex:pageBlockSectionItem>
- </apex:pageBlockSection>
- </apex:pageBlock>
- </apex:form>
- </apex:page>
Note:
Since JavaScript all identifiers are case sensitive. So make sure while initializing identifiers.
The variables lastName and lastname, are two
different variables.
The functions myFunction and myfunction, are two
different functions.
JavaScript does not interpret Var; as var.
No comments:
Post a Comment