0

I am trying to show a popup when picklist is selected but I am unable to do I tired this https://developer.salesforce.com/forums/?id=906F0000000DDKiIAO dint work :(

    <apex:outputPanel">
      <apex:outputLabel>Pick one</apex:outputLabel><br/>
      <apex:selectList id="picklst" value="{!selectedValue}" size="1" required="TRUE" multiselect="FALSE">
          <apex:selectOptions value="{!Lst}"/>
          <apex:actionSupport event="onchange" action="{!func}"/>
      </apex:selectList>
    </apex:outputPanel>

I mean it works but doesn't execute

   <apex:actionSupport event="onchange" action="{!func}"/> 

as this render the VF components to display form page. I want to display a popup when someone change to value1 to value2. saying data will be lost. Any ideas

4
  • Is that function JavaScript function? Commented Jul 7, 2018 at 3:58
  • @ Naruto-sdfc - Yes Javascript Function and called in apex:selectList and it through an error :(
    – Mentee
    Commented Jul 7, 2018 at 4:23
  • 1
    You might want to check how you calling function. That syntax is like your calling an apex function. That should’ve been onchange =“function()” Commented Jul 7, 2018 at 4:39
  • @naruto-sfdc - it works but doesn't execute <apex:actionSupport event="onchange" action="{!func}"/> as these render my components to display page. I want to display a popup when someone change to none to somevalue. saying are you sure you wanna change. any ideas
    – Mentee
    Commented Jul 7, 2018 at 6:09

1 Answer 1

2

You need to make changes in your Actionsupport to make it work. As you want to call JavaScript so instead of action use onsubmit. Set rerender to none to stop the page reload.

<apex:actionSupport event="onchange" onsubmit="alert('You will lost value');" rerender="none"/>

But in your use case you don't need actionsupport as apex:selectList also support onchange event. You can simplyuse that as well.

<apex:selectList id="picklst" value="{!selectedValue}" size="1" required="true" multiselect="false" onchange="alert('You will lost value');">

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .