I am trying to execute a jQuery Validation plugin but getting a little issue. On the same button I have to first perform validation, and when the validation successful it execute some other jQuery code by getting the id of this button. for example view the code below.
$(function () {
$("#form-insert").validate({
rules: {
tbRollNo: "required"
},
messages: {
tbRollNo: "Required Field"
}
});
$("#insertstd").click(function (e) {
e.preventDefault();
debugger
$.ajax({
type: 'POST',
url: '/Home/student',
data: {
Insert: true,
RollNo: $('#tbRollNo').val(),
Title: $('#tbTitle').val(),
},
success: function () {
},
error: function () {
alert("Oh noes");
}
});
});
The button code is following:-
<input id="insertstd" type="submit" name="btnSubmit" value="Submit" />
So when I click the above button it directly read the $("#insertstd").click function but does not start validation, and when I remove the id="insertstd" from button then it perform validation.
So I want that it should first perform validation and then run $("#insertstd").click function.