Alert box for cfform

This is a simple example where an alert box is displayed to the user before performing a critical operation. It is sometimes necessary to have a confirmation from the user, so we'll use an alert to do it. If the user clicks on "Yes", we continue, otherwise, we cancel.


This is a simple example where an alert box is displayed to the user before performing a critical operation. It is sometimes necessary to have a confirmation from the user, so we'll use an alert to do it. If the user clicks on "Yes", we continue, otherwise, we cancel.

Here is the code

var myClickHandler = function (evt){ if (evt.detail == mx.controls.Alert.OK){ alert("Records deleted","Completed"); } } alert("Are you sure you want to remove all records?", "Warning", mx.controls.Alert.OK | mx.controls.Alert.CANCEL, myClickHandler);

Note that the function alert() returns true as soon as the alert is triggered. It doesn't wait for the user response. That means we cannot do if(alert("")){ do something } else {cancel} because it will always go to "do something" regardless of what the user responds. That is why we need to make the event handler function that receives the actual response.

View live example
Download source