I am using the jQuery validate plugin to validate my form. I would like to tie several pairs of fields together such that if one field has a value, the other is required to have a value also. Essentially both fields (both text inputs) must either both have a value or both not have a value. Is anyone aware of a good way to accomplish this?
if you look at the "rules" section's example code in the documentation page, there is a depends
field you can set.
something like the following (this is right off my head, not tested):
... secondInput: { required: function(element){ return $("#firstInput").val()!=""; } } ....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With