I have a form with a submit and cancel button and I want to show a different `confirm` message bepending on which button is clicked so this is what I've come up with. 

```
function confirmDialog(buttonId) {
    switch (buttonId) {
        case "cancel":
            var result = confirm("cancel message");
            submitForm(result);
            break;
        case "submit":
            var result = confirm("Submit message");
            submitForm(result);
            break;
    }
};

```

And my `submitForm` function looks like

```
function submitForm(result) {
    console.log(result); //this is false when I click cancel in the confirm box
    if (result && $("#myform").valid()) {
        $("#myform").submit();
    }
    else {
        return false;
    }
};

```

Now my issue is that when I click cancel the form still gets submited. Can someone tell me what I'm doing wrong please. I have `return false;` in my `else` condition so I really don't know why it still submits the forms. 

I've looked at the following questions but I'm still facing the issue

[jQuery Still Submits Ajax Post Even When “Cancel” is clicked on Confirm Dialog](https://stackoverflow.com/questions/23051989/jquery-still-submits-ajax-post-even-when-cancel-is-clicked-on-confirm-dialog)

[javascript confirm (cancel) still submits form when returning false](https://stackoverflow.com/questions/32988915/javascript-confirm-cancel-still-submits-form-when-returning-false)

**Edit:** Cancel button html as requested 

```
<button type="submit" id="cancel" class="btn btn-danger btn-block" value="Cancel">Cancel</button>

```

**Further Edit**

I call the `confirmDialog` function in the click event the appropriate button as follows:

```
 $("#cancel").click(function () {
    var buttonId = $(this).attr("id");
    confirmDialog(buttonId)
});

```