Below is the JS code I've used to update the status field on order object when clicking on custom cancel button.
The issue i am facing here is when clicking on cancel button, confirm pop up shows up asking if I want to continue with cancellation by clicking ok or cancel the process by clicking cancel on pop up.
The status field is being updated even when i click on cancel on the pop up message.
Here I only want to perform a field update when user clicks on ok on the pop up.
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}
try {
var url = parent.location.href;
var updateRecords = [];
var update_Order = new sforce.SObject("Order");
update_Order.Id ="{!Order.Id}";
update_Order.Status="Cancelled";
updateRecords.push(update_Order);
result = sforce.connection.update(updateRecords);
confirm('Are you sure you want to cancel?');
parent.location.href = url;
} catch (e) {
alert (e);
}