i have two submit buttons on my mvc application.
1.
<input type="submit" class="btnsubmit" value="Add Subscription" name="Submit" />
2.
<input class="cancel" type="submit" value="Cancel" onclick="CheckBox()"/>
In document ready function i have this.
$(document).ready(function () {
$('#form').submit(function () {
var $fields = $(this).find('input[name^="chk_"]:checked');
if (!$fields.length) {
alert('You must select at least one record !');
return false; // The form will *not* submit
}
});
});
Basically one can submit the form only when atleast one checkbox is checked, but i want that user be able to hit Cancel and go back to home page. But right now, when i click on Cancel Button, the app tries to submit the page, and checks if any checkboxes were selected, which i don’t want on Cancel Button Click.
Any approaches/ Views ? Thanks !!
change
tye=submittotype=button. because,type=submitby default make a form submission.So it will look like:Or, you can change the button like: