0

I have a pick list called System Size(System_Size_SUB_2013__c). When I select an value from pick list I want to give an alert to the user. (Only for a One value, Not all of them). Any idea? Thanks

<apex:inputField value="{!Product_Brief__c.System_Size_SUB_2013__c}" required="true"/>
  • 1
    Have you tried using the onchange tag? You can embed some javascript in there. Like this: <apex:inputField value="{!Product_Brief__c.System_Size_SUB_2013__c}" required="true" onchange="executeFunctionFoo();"/> – Jason Hardy Jul 28 '15 at 20:38
  • No I Have not . I will try onchange="executeFunctionFoo(); Thanks – Suneth Jul 28 '15 at 20:43
1

This might help you

<apex:page standardController="lead">
    <script>
        function popup(){

            alert("Hello\nHow are you?");           

            }

    </script>

    <apex:form >
        <apex:outputField value="{!lead.phone}"/>       
        <apex:inputField onchange="popup();" value="{!lead.status}" />
     </apex:form>
</apex:page>
  • Thanks, This is working but I only want for one value. In my code it will alert for every value. Any idea how to change it to only one value. – Suneth Jul 28 '15 at 20:59
  • You are using inputfield ,you are not using any custom controller it means value you are not storing anywhere, whatever value you are selecting , if we use if condition it might only pickup the value which is already stored. you need to store this value through get set properties – Ashish Jul 28 '15 at 21:57
1

If you need for specific value than you would need get the id of that value and whenever selected it shall throw the pop up. Refer to following snippet : document.getElementById("{!$Component.xyz}:0"); where "xyz" is id of the the entire picklist component and "0" is the index value.

  • 1
    But I think that value is not stored yet,so this might not work, when a user selects the picklist value it is not save until unless user saves the value. – Ashish Jul 28 '15 at 21:51
1

Try this

<apex:form id="theForm">
    <apex:pageBlock id="thePageBlock">
        <apex:pageBlockSection id="thePageBlockSection">
            <apex:inputField id="myPicklist" value="{!Product_Brief__c.System_Size_SUB_2013__c}" required="true" onchange="myPicklistChanged();"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>

<script>
    function myPicklistChanged()
    {
        var myPicklistElement = document.getElementById('{!$Component.theForm.thePageBlock.thePageBlockSection.myPicklist}');
        var myPicklistValue = myPicklistElement.options[myPicklistElement.selectedIndex].value;

        if (myPicklistValue == '2000L SUB')
        {
            alert('Your Message');
        }

    }
  • 1
    I believe it does work, though you have lot of missing end tags </apex:pageblock> :) – Ashish Jul 29 '15 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.