Troubles using jquery on a form
I'm trying to use Jquery in order to validate a form's input. On top of
that, I want to auto-fill some fields if they are left blank. Here is how
I proceed :
$(form).submit(function () {
var result = true;
var timeRegex = /^([0-9]|0[0-9]|1[0-9]|2[0-3]):([0-5][0-9])$/;
if ($("#newStartTime").val().length == 0)
$("#newStartTime").val("00:00");
if (!timeRegex.test($("#newStartTime").val())) {
$("#newStartTime").wrap("<div class='error' />");
result = false;
}
return result;
});
What's happening here is that the input is set to 00:00, but the submit is
rejected (and the field wrapped as an error). If I re-click on submit, it
works fine.
The way I see things, Jquery doesn't treat the modifications made after
the 'submit' was called. If that's the case, is there a way to achieve
what I want without using ".submit()" twice ? If I'm mistaken, what's
wrong ?
No comments:
Post a Comment