I would really appreciate some help with form validation in JQuery. I am a noob, so apologies in advance if this is really simple.
Basically, I want to validate a form on a questionnaire. There are two types of inputs in the form - an input, which is using JQuery Range Slider on a scale of 1 to 5, and textarea input boxes, where the user can type thoughts into.
So the validator plugin works fine and checks all the fields and then marks in red which are incomplete. My problem comes in when the user has the filled the required information in. I can get the textarea to validate and remove the red label as soon as the user focuses out of the box, but the input will not validate if it has already validated once and picked up an error.
Some of my HTML Form:
<tr>
<td>Rate how confident you feel about your knowledge on the subject</td>
<td class="slider-holder">
<div class="slider num"></div>
<input class="sliderValue validateFormClass" type="text" readonly="true" name="fb_33" required />
</td>
</tr>
<tr>
<td>List three important concepts or ideas that you learned in this course</td>
<td class="slider-holder">
<textarea name="fb_34" class="textAreaFBSurvey validateFormClass" required></textarea>
</td>
</tr>
My JQuery Validation code:
$(document).ready(function () {
$('.form-required').validate({
onclick: false,
focusInvalid: false,
focusCleanup: true,
errorPlacement: function (error, element) {
$('.error-message').removeClass('hidden');
$(element).closest('tr').addClass('error');
},
onfocusout: function (error, element) {
$('textarea.valid').closest('tr').removeClass('error');
},
submitHandler:function (form) {
form.submit();
},
});
});
What I am trying to achieve is that should a user submit an incomplete form, the missing fields will be marked as red. As soon as that user then fills out the remaining fields, be it a textarea or an input, the 'error' classes would then be removed without having to click the submit button. This just makes it more visually appealing and easier to understand that all fields are complete.
I have tried in vain for 2 days now and not been able to figure this out, so any direction or a simple 'this is impossible' will be much appreciated.
Many thanks
.errorclass from ?$('.valid').closest('tr').removeClass('error');<form></form>tags and a submit button would be helpful. Your version of the validation plugin (1.7) is also too old to work with jQuery 2. jsfiddle.net/m0skkb6s