validation of radio button

i have a form with 4textboxes tied to radio buttons. the validation should be done only for the textbox whose radio button is selected. pl suggest.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head> 
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
  $("#bb").validate({
    rules: {
      boy: "required",
      girl: "required",
	  man: "required",
      woman: "required"
    },
		messages: {
			boy: {
				required: "Please enter a boy",
				minlength: "Your boy must consist of at least 4 characters"
			},
			girl: {
				required: "Please enter a girl",
				minlength: "Your girl must consist of at least 4 characters"
			},
			man: {
				required: "Please enter a man",
				minlength: "Your man must consist of at least 4 characters"
			},
			woman: {
				required: "Please enter a woman",
				minlength: "Your woman must consist of at least 4 characters"
			}
		}
  });
});
</script>
</head>
<body>
<form name="bb">
<div id="mybuttonradios">
<input type="radio" name="a" value="b" />boy<input type="text" name="b" onfocus="this.parentNode.getElementsByTagName('input')[0].checked=true;" /><br/>
<input type="radio" name="a" value="g" />girl<input type="text" name="g" onfocus="this.parentNode.getElementsByTagName('input')[2].checked=true;" /><br/>
<input type="radio" name="a" value="m" />man<input type="text" name="m" onfocus="this.parentNode.getElementsByTagName('input')[4].checked=true;" /><br/>
<input type="radio" name="a" value="w" />woman <input type="text" name="w" onfocus="this.parentNode.getElementsByTagName('input')[6].checked=true;" />
<input type="button" value="check">
</div>
</form>
</body>
</html>

Open in new window

yingwhoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
0
yingwhoAuthor Commented:
leakim

my question is different as it has tied up with textboxes, we check if the radio button selected and the associated text box empty? and shout not validate other textboxes even if the have values. not regular radio group. pl advice.
0
hieloCommented:
instead of:
 boy: "required",

you need to specify a "dependency expression". Since boy depends on the first radio being checked, that should be:
 boy: {required:'input[value="b"]:checked'}
likewise for girl:
 girl: {required:'input[value="g"]:checked'}

also, notice that it is an object not a string. Lastly, your "message" section has messages for "required" and for minlength, BUT you have no minlength in the rules. You need to add them in the rules as well:

 boy: {required:'input[value="b"]:checked', minlength: 4}
 girl: {required:'input[value="g"]:checked', minlength: 4}

etc. Wasn't that easy?
:)

Regards,
Hielo
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yingwhoAuthor Commented:
thanks guys.
0
leakim971PluritechnicianCommented:
Thanks for the points!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.