+ Start a Discussion
Ken_KoellnerKen_Koellner 

can't get javascript confirm() to call action in my custom controller.

I want to put up a confirmation dialog before calling an action in a custom controller.  The first command button shown below works.  For the second one, I tried to create the script as shown below but the page doesn't compile. I get the error "Save error: Unknown property 'MyCustomerController.save'.  But that's the same method that the regular button calls and that button compiles???

 

<apex:commandButton value="Save to Mass Sample " action="{!save}" />    
<apex:commandButton value="Javascript Save to Mass Sample " onclick="javascript:confirmSave();" />  

 

<script>
    function confirmSave(){
      var answer = confirm("Are you sure you want to create samples?")
      if (answer){
        window.top.location = "{!URLFOR(save)}";
        <!-- window.top.location = "{!save}";   Tried it this way too. sample problem -->
      }
      else {
        alert("No samples have been created.")
      }
    }
</script>
 
 

TehNrdTehNrd

You'll need to use actionFunction

 

<apex:commandButton value="Javascript Save to Mass Sample " onclick="confirmSave();" />

<apex:actionFunction name="doSave" action="{!save}" rerender="something"/>

 

<script>
    function confirmSave(){
      var answer = confirm("Are you sure you want to create samples?");

      if (answer){
       doSave();

      }else{

        alert("No samples have been created.");

     }
    }
</script>

 

 

 

WilmerWilmer

Hi, According to your example, is there any way to read a custom label value instead of setting a hard coded message?

 

Regards,

 

Wilmer

Naveen KNNaveen KN
Implement custom dialog box in salesforce lightning 

https://www.codekiat.com/2019/07/confirm-dialog-in-salesforce-lightning.html

--
Naveen K N