I'm working on a dynamic form where based on a visitors selection of radio buttons certain <div> text and additional fields are shown or hidden. I would like to make some of these additional fields required but only if they are shown. (I tried making them required even when they are hidden and then the form won't submit because it won't pass validation and the user can't do anything about it... stupid me! :-))
Anyway, here's the script I'm using, thanks to some help from another Daniweb user, and I'm not sure how to tweak it to get it to require fields only if they are visible.
$(document).ready(function(){
//Hide these fields initially
$("#dad_address").hide();
$("#mom_address").hide();
$('#bothparents').click(function() {
$("#dad_address").toggle(this.checked);
$("#dad_address").hide();
$("#mom_address").hide();
});
$('#dadaddress').click(function() {
$("#dad_address").toggle(this.checked);
$("#mom_address").hide();
});
$('#momaddress').click(function() {
$("#mom_address").toggle(this.checked);
$("#dad_address").hide();
});
});
Thanks in advance!
Fcvolunteer