Skip to content Skip to sidebar Skip to footer

Html Form Validation - Conditional Based On Radio Button Selection

I have an HTML form and I'm using the JQuery Validate plugin to require some form fields to be mandatory. I have a radio button field with 3 options: Hours Days Unsure and another

Solution 1:

From: https://stackoverflow.com/a/19546185/1477051

jQuery Validate actually directly supports this, using dependency expressions.

All you need to do is change your validate options like this:

$('#myform').validate({
    rules: {
        fieldA: {
           required:'#checkA:checked'
        }
    }
});

That's it!

I've used it on your code here: http://jsfiddle.net/xJBX9/1/

Post a Comment for "Html Form Validation - Conditional Based On Radio Button Selection"