I've a button within my ASP.Net MVC 5 Razor View
@using (Html.BeginForm("MyAction", "MyController", FormMethod.Post, new { id = "myForm" }))
{
<button type="submit" class="btn btn_d fl sepV_a" id="btnNotify" name="btnNotify"><span>Notify</span></button>
}
When it is clicked I call a JQuery function which asks the user whether or not they still wish to continue with the Submit
<script type="text/javascript">
$(document).ready(function () {
$("#btnNotify").click(ConfirmNotify);
function ConfirmNotify() {
if (confirm('Are you sure you wish to continue?')) {
$("#btnNotify").attr('disabled', 'disabled');
return true;
} else {
return false;
}
}
});
</script>
If the user clicks OK to confirm with the Submit, I then want to disable the Notify button.
Unfortunately the code above disabled the Notify button when the user clicks OK to the prompt, however, the Submit form does not then occur.
If I swap the lines $("#btnNotify").attr('disabled', 'disabled');
and return true;
about to this
function ConfirmNotify() {
if (confirm('Are you sure you wish to continue?')) {
return true;
$("#btnNotify").attr('disabled', 'disabled');
} else {
return false;
}
}
The Form gets Submitted when the user clicks OK, but the button Notify doesn't get disabled, i.e., the user can then click the Notify button multiple times.
Does anyone know how to correct this? Any advice greatly appreciated.
Thanks.