Reputation: 209
I am working on a MVC asp.net project and I have a created a button that when click, I need a confirm box to pop up and say "Yes" and "No" and possibly cancel.
My code is below
if (Model.AStatusId == AssetManager.Utility.AMConstants.AssetStatus_Deployed)
{
<div class="col-sm-12 text-center m-t-20">
<input type="submit" class="btn btn-success" value="Check In"
onclick="return ValidateCheckInAsset();" />
</div>
}
<script>
function ValidateCheckInAsset() {
var label = "";
var flag = 0;
if ($("#SourceID").val().length == 0) {
label += "Are you sure you want to Check In? \n";
flag = 1;
}
if ($("#TrackingNumber").val().length == 0) {
label += "Are you sure you want to Check In?";
flag = 1;
}
if (flag == 1) {
alert(label);
return false;
}
else
return true;
}
</script>
At the moment is displaying an alert label, which I am using for a different button so I know this isn't my solution but I am having problems creating the actual confirm query.
Any help would be very much appreciated.
Upvotes: 0
Views: 390
Reputation: 1142
Ok. First of all due to the fact that i can see you are using jQuery i would advise to stop using onclick event on the HTML element.You can search and find out that is depreciated. You can add a different class to the input element in order not to interfere with possible future buttons with the same bootstrap classes.
So your HTML will be
<div class="col-sm-12 text-center m-t-20">
<input type="submit" class="btn btn-success confirmationBtn" value="Check In" />
</div>
And your event listener using the window confirm method
$(".confirmationBtn").click(function() {
if (confirm("Are you sure ??")) {
} else {
}
});
Upvotes: 1