1

I have the following code

<apex:commandButton action="{!AuthM.saveList}" id="saveButton" value="Save" onclick="nullDatePopup()"/>
        <script>
        function nullDatePopup(){
            var f='{!AuthM.flag}';
            if(f==1)
            alert("Hi");
        }
</script>

Here flag is a variable from the AuthM class. What I want is the alert to display after {!AuthM.saveList} method has been called and set the value of flag. But the alert is not showing at all. Can someone tell me where am I going wrong?

2
  • ohh means once your method called i.e. AuthM.saveList after that display alert ?
    – Ratan Paul
    Jan 21, 2016 at 13:00
  • @Ratan yes. that is exactly what I want
    – Rimii
    Jan 21, 2016 at 13:01

2 Answers 2

1

Use oncomplete attribute.. It will call once first action completed.

So It will called after your controller method execution completed.

To get the update {!AuthM.flag} value. You need to rerender your javascript inorder to get updated value.

<apex:commandButton action="{!AuthM.saveList}" id="saveButton" value="Save" 
                                          oncomplete="nullDatePopup()" rerender="op1"/>

<apex:ouputPanel id="op1">
<script>
function nullDatePopup(){
      var f='{!AuthM.flag}';
      if(f==1)
      alert("Hi");
 }
 </script>
</apex:ouputPanel>
0
  1. You are calling your method on onClick which called just before the apex method call and never get true

You just need to do following :

  <apex:commandButton action="{!AuthM.saveList}" id="saveButton" value="Save" reRender="alertBlock"/>
<apex:outputPanel id="alertBlock">
<script>

    var f='{!AuthM.flag}';
    if(f==1)
    alert("Hi");

</script>
<apex:outputPanel>

OnComplete call will not work as it will call a already rendered javascript block which have old class values.

6
  • SFDC Suppose your <apex:outputPanel id="alertBlock"> inside your <apex:page> and you are trying to refresh your <apex:page> then your your script will run again that will be unnecessary correct ?
    – Ratan Paul
    Jan 21, 2016 at 13:11
  • If you need to apply check on updated value, you have to fetch them any how . Jan 21, 2016 at 13:13
  • Yeah Yeah Correct.. Just saying it will be better option to use oncomplete attribute to call javascript function instead each time run when you rerender outputpanel correct ?
    – Ratan Paul
    Jan 21, 2016 at 13:14
  • When you call onComplete call, and want to check on some apex property value, you will always check on old values of ape until it is refreshed. Jan 21, 2016 at 13:24
  • @SFDCGOD I tried your way. It is creating a different problem in the code.. Is it possible to give a javascript popup? Its extremely urgent
    – Rimii
    Jan 25, 2016 at 6:06

You must log in to answer this question.

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