/    Sign up×
Community /Pin to ProfileBookmark

radio button validation

Im having difficulties with a small validation script. I have a group of two radio buttons (radio group called housing) and depending on what radio it tries to validate if a checbox has been selected within the group. Here is my HTML:
[B]
<form action=”registrationconfirmation.htm ” name=”frmCSC” method=”post” onsubmit=”return validForm(this)”>

<p>Housing Family
<input name=”housing” type=”radio” value=”single” “onclick=”getTotal();” />

1
<input name=”familydate21″ type=”checkbox” id=”familydate21″ value=”Y” onclick=”getTotal();” />
2

<input name=”familydate22″ type=”checkbox” id=”familydate22″ value=”Y” onclick=”getTotal();” />
3
<input name=”familydate23″ type=”checkbox” id=”familydate23″ value=”Y” onclick=”getTotal();” />
</p>
<p>Housing Single
<input name=”housing” type=”radio” value=”family” onclick=”getTotal();” />
1
<input name=”singledate21″ type=”checkbox” id=”singledate21″ value=”Y” onclick=”getTotal();” />
2
<input name=”singledate22″ type=”checkbox” id=”singledate22″ value=”Y” onclick=”getTotal();” />
3
<input name=”singledate23″ type=”checkbox” id=”singledate23″ value=”Y” onclick=”getTotal();” />
</p>
<p>
<input type=”submit” name=”Submit” value=”Submit” />
</p>
[/B]

And here is the javascript i wrote but it is not validating..any suggestions?
[B]
if(theForm.housing[1].checked = true) {
if((theForm.familydate21.checked == false) && (theForm.familydate22.checked == false) && (theForm.familydate23.checked == false))
{
alert(“Please choose at least one option from the ‘Family housing’ section.”);
theForm.familydate21.focus();
return (false);
}
}

if(theForm.housing[0].checked = true) {
if((theForm.singledate21.checked == false) && (theForm.singledate22.checked == false) && (theForm.singledate23.checked == false))
{
alert(“Please choose at least one option from the ‘Single housing’ section.”);
theForm.singledate21.focus();
return (false);
}
}

[/B]

anyone know where im going wrong here? thanks you guys!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@PittimannFeb 15.2005 — Hi!

This example should do a part of what you want, but if you play with it, you might find out, what else could be usefull:[code=php]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Example</title>
<script language="JavaScript" type="text/javascript">
<!--
function getTotal(){
theForm=document.myform
if(theForm.housing[0].checked){
if(!theForm.familydate21.checked&&!theForm.familydate22.checked&&!theForm.familydate23.checked){
alert("Please choose at least one option from the 'Family housing' section.");
theForm.familydate21.focus();
return false;
}
}
if(theForm.housing[1].checked){
if(!theForm.singledate21.checked&&!theForm.singledate22.checked&&!theForm.singledate23.checked){
alert("Please choose at least one option from the 'Single housing' section.");
theForm.singledate21.focus();
return false;
}
}
}
//-->
</script>
</head>
<body>
<form name="myform" action="#" method="" onsubmit="">
<p>Housing Family
<input name="housing" type="radio" value="single" onclick="getTotal();"> 1
<input name="familydate21" type="checkbox" id="familydate21" value="Y" onclick="getTotal();"> 2
<input name="familydate22" type="checkbox" id="familydate22" value="Y" onclick="getTotal();"> 3
<input name="familydate23" type="checkbox" id="familydate23" value="Y" onclick="getTotal();">
</p>
<p>Housing Single
<input name="housing" type="radio" value="family" onclick="getTotal();"> 1
<input name="singledate21" type="checkbox" id="singledate21" value="Y" onclick="getTotal();"> 2
<input name="singledate22" type="checkbox" id="singledate22" value="Y" onclick="getTotal();"> 3
<input name="singledate23" type="checkbox" id="singledate23" value="Y" onclick="getTotal();">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>[/code]
I hope, it gets you started. If not, please specify, what the stuff is supposed to do.

Cheers - Pit
Copy linkTweet thisAlerts:
@vicpal25authorFeb 15.2005 — nice that works, yeah i think there was a conflict with the form name..thanks a million! ?
×

Success!

Help @vicpal25 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...