I am trying to submit my form, however I added some jquery for validation, which works:
$(function validateForm() { $("#newMonoReading").on('focusout', function () { var str = ""; var initialMonoReading = $('#InitialMonoReading').val(); var newMonoReading = $('#newMonoReading').val() if (~~newMonoReading < ~~initialMonoReading) { $('#MonoErrorMessage').text("New Mono Readings must be MORE than existing"); $('#MonoErrorMessage').show(); return false; } else { $('#MonoErrorMessage').hide(); } }); });
But the problem is the submit button
<input type="submit" value="Submit" class="btn btn-primary">
If there is an error, the submit button is still working, I need it to not display error messages and then send them, but I tried using onsubmit for the form, but it doesn’t work, it still submits, although the value is lower and a message appears about the error.
This is html.BeginForm. I think the error may be here. I'm not sure.
<div class="modal-body"> @using (Html.BeginForm("Save", "ReadingsEntry", FormMethod.Post, new { enctype = "multipart/form-data", onsubmit = "validateForm()" })) {
Any ideas
m ali source share