I have a form using JQuery validation plugin.
<label>
<input name="Distribution[]" type="checkbox" id="dist_europe" class="required minlength:1" value="Europe" /> Europe
</label>
<select name="Europe[]" size="5" multiple id="Europe">
<option value='Albania'>Albania</option>
<option value='Andorra'>Andorra</option>
<option value='Austria'>Austria</option>
</select>
I need to do 'conditional' validation. eg. If checkbox is selected, make sure at least one item in 'select option is selected'.
$(document).ready(function(){
$("#commentForm").validate({
rules: {
Europe: {
required: "#dist_europe:checked",
minlength: 1
}
},
messages: {
Europe: "Please select at least 1 country"
}
}
})
The issue I am facing now is :
- I am able to detect that the checkbox is selected.
- However, I am not able to check the 'select' array, Europe[]
- If I remove the array, and name it Europe, I will be able to detect that at least one item is selected. But, doing that will mean the backend PHP script will not be able to process the multiple select in the array.
How do I work around this? Thanks