Please someone help me, I really stuck on this for the whole day. I have a php form (multiple page) with different types of input(radio, checkbox, etc). what I need is :
If user didn't fill required fields and pressed the continue button, he should receive an error message BESIDE or ABOVE that field.
If he forgot to fill some fields, other input fields should not be cleared (since I don't want him/her to get bored of re-answering all those questions again)
This is what I have tried so far with JQuery plugin: (sorry, I could not paste all the code since it was too long)
<form name="MovieSurvey" id="formId" action="page2.php" method="post" />
<fieldset id = "q1"> <legend class="Q1"></legend>
<label> What is your gender?<span>*</span></label>
<div class="fieldset content">
<div class="error_message_holder"></div>
<Input type = 'radio' Name ='q1' value = 'male'>Male
<Input type = 'radio' Name ='q1' value = 'female'>Female
</div>
</fieldset>
....
....
<input type="submit" name= "continue1" value="Continue" />
</form>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://jqueryvalidation.org/files/dist/jquery.validate.min.js"></script>
<script src="http://jqueryvalidation.org/files/dist/additional-methods.min.js"></script>
<script>
$(document).ready(function() {
$('#formId').validate({ // initialize the plugin
rules: {
q1: {
required: true,
},
q2: {
required: true,
},
q5: {
required: true,
},
q6: {
required: true,
}
},
errorPlacement: function(error, element) {
error.html('Please fill this field');
if(element.closest('.fieldset content').find('label.error').length==0){
error.insertBefore(element.closest('.fieldset content').find('.error_message_holder'));
}
}
});
});
</script>
</div>
</fieldset>
</body>
</html>
It works almost well, the only problem is that the error message is shown between radio-button and label! (This is when I don't write the errorPlacement: function part), in order to fix it I added the placement part but now it shows nothing!
Could someone help me fix it?
Thanks,