Using jQuery version 1.4.2 and Validation plugin version 1.8.1
I have a textbox that is required only if a checkbox is checked.
If I declare the rule in the validation method it works flawless:
$("#tipoEntradasForm").validate({
rules: {
cantidad_aforo: { required: "#aforo_limitado:checked" }
}
})
but for the sake of simplicity, I need to declare it in an attribute on the input tag.
I tried several variations, all of them something like
<input
name="cantidad_aforo" id="cantidad_aforo" type="text"
class="anchofecha"
required="#aforo_limitado:checked"
min="1"
value=""
/>
but with no success.
Can anybody tell me if I am doing something wrong and what should I do instead? Any advice would be much appreciated.
Thanks !
Input’s attribute ‘required’ is not the same thing as the jquery validation’s method. So you can’t do it like this.
So the original code is the simpliest way to get what you want.