Find your content:

Search form

You are here

Custom JS confirm button for IF

 
Share

I need a confirmation alert box to pop up if shipping is set to 0. If the user pressed ok it should redirect to the quote, if the user presses cancel it should stay on the current page.

I am using a custom page detail button set to OnClick JavaScript on a Standard Quote Layout.


Attribution to: Carl S

Possible Suggestion/Solution #1

The broadest answer I can give to the broadest question would be something like:

On your Visualforce commandButton, set the onclick attribute to be a javascript function call

<apex:commandButton onclick="return showConfirmation();" action="{!SendOrder}" value="Send Order"/>

Then in your Visualforce page, have yourself a bit of javascript, within an apex:output panel to do the javascript alert box. If OK is selected the page will "continue" on to the action command of the button, if false is selected, the user is returned to the page:

<apex:outputPanel id="sendScript">
  <script type="text/javascript">
  function showConfirmation() {
    var orderSize = '{!orderSize}';
    if(orderSize == 0) {
      return confirm('That is zero');
    }
  }
  </script>
</apex:outputPanel>

There is a merge field in there which examines the orderSize.. but in order to keep this in line with the current state of the order object, it needs to be rerendered whenever this value changes..

Therefore, finally, on your input field for the order size, or whatever component determines/changes ordersize, add a rerender="sendScript" or an actionSupport to rerender this Javascript panel (which re-merges the orderSize value)

<apex:actionSupport event="onchange" rerender="sendScript" />

Do this whereever orderSize can be altered and the javascript block will be redrawn so the logical comparison remains relevant.


Attribution to: Simon Lawrence

Possible Suggestion/Solution #2

Managed to resolve this using the following code on a Page Detail button set to OnClick Javascript:

if ('{!Quote.ShippingHandling}' == "£0.00")
{
if (confirm('Are you sure you want to quote with no shipping cost?')) {
window.location = 'APEX URL/?id={!Quote.Id}';
}
} else {
window.location = 'APEX URL/?id={!Quote.Id}';
}

Attribution to: Carl S
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/30544

My Block Status

My Block Content