0

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.

Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61
Padgey85
  • 211
  • 1
  • 2
  • 7
  • A standard confirm box with `confirm()` only has 2 buttons, you need to create a modal containing 3 buttons by yourself. What do you want to do when each button clicked by user? – Tetsuya Yamamoto Jan 14 '19 at 09:38
  • This might come handy if you need three buttons: https://stackoverflow.com/questions/9091001/how-to-show-confirmation-alert-with-three-buttons-yes-no-and-cancel-as-it – LocEngineer Jan 14 '19 at 10:09

1 Answers1

1

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 {

  }
 });
kostas.kapasakis
  • 920
  • 1
  • 11
  • 26