I have a field named “GROSS AMOUNT”
If the gross amount is zero, then the javascript message confirmation asks the user whether the user should continue saving with zero amount and if the user presses cancel, even the server side save button should not be active, it should return back to the panel of the gross amount.
I have used the following code for the client side.
function show_confirm() {
// var txttemp = document.getElementById("<%=txtSAmt.ClientID %>").value;
var menu = $find("<%= this.txtSAmt.ClientID %>");
var check;
if (menu != null) {
check = menu.get_value();
}
if (check == '0') {
var r = window.confirm("Gross Settlement Amount is 0.Press Cancel to Change, Press OK to save anyway");
if (r == 'false') {
}
}
}
Please let me know that if the client clicks cancel, it should not fire the btnSave on the server side.
I assume this is an event handler for the onclick event of
btnSave.First,
rwill never equal"false"becauseconfirm()returns a boolean, not a string. You need to comparertofalse(without quotes). Actually, you don’t need to comparerto anything sinceris already a boolean. Sor == falseis the same as!r.You can use
e.preventDefault(). You’ll need to add theeparameter to your function definition:If you are calling
show_confirm()like this:You’ll need to change that to pass the
eventobject:Alternatively, you can just return
falsefrom your event handler. Again, if you are callingshow_confirm()as above, you’ll need to change it to:You can change your function to this: