/    Sign up×
Community /Pin to ProfileBookmark

Radio Group Validation

Dear Users,

I have 2 radio groups Yes/No option with values 1/2 , where 1 = Yes and 2 = No. How do I do a validation if I select both No to pop up message open and say “Please select at least one Yes”, below is the simple code I did for the buttons. Thank you for all your help

<form name=”form1″ method=”post” action=””>
<p>
<label>
<input type=”radio” name=”RadioGroup1″ value=”1″ id=”RadioGroup1_0″>
Yes</label>
<br>
<label>
<input type=”radio” name=”RadioGroup1″ value=”2″ id=”RadioGroup1_1″>
No</label>
<br>
</p>
<p>
<label>
<input type=”radio” name=”RadioGroup2″ value=”1″ id=”RadioGroup2_0″>
Yes2</label>
<br>
<label>
<input type=”radio” name=”RadioGroup2″ value=”2″ id=”RadioGroup2_1″>
No2</label>
<br>
</p>
<p>
<label>
<input type=”submit” name=”submit” id=”submit” value=”Submit”>
</label>
</p>
</form>

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@spacemocauthorSep 15.2010 — I did tryed to use this but it's doesnt work

function validateForm(objForm)

{

var idTypeBooking = 0;

if(RadioGroup2_0 == 2 && RadioGroup2_1 == 2){

Do something here (pop up message and not allowe to submit form)

}else {
do nothing

}
}
Copy linkTweet thisAlerts:
@FangSep 15.2010 — [CODE]function validate(f) {
if(!f.RadioGroup1[0].checked && !f.RadioGroup2[0].checked) {
alert('Please select at least one Yes');
return false;
}
return true;
}
[/CODE]
Copy linkTweet thisAlerts:
@spacemocauthorSep 15.2010 — that is working well but there is one issue as I am using a Spry Validation fro a dreamweaver and have Spry Validation on the Radio Group, which is disabled after applied the function you created. Any idea how to solve that ?
Copy linkTweet thisAlerts:
@spacemocauthorSep 15.2010 — And that the code

<form name="form1" method="post" action="index2.php" onSubmit="return validate(this);">
<p><span id="spryradio2">
<label>
<input name="promotion4" type="radio" id="RadioGroup2_0" onClick="MM_showHideLayers('spryselect1','','show','select1','','show')" value="1">
Yes</label>
<label>
<input name="promotion4" type="radio" id="RadioGroup2_1" onClick="MM_showHideLayers('spryselect1','','hide','select1','','hide')" value="2"></p>


</form>
Copy linkTweet thisAlerts:
@spacemocauthorSep 16.2010 — I think so I have to modyfie this part of the code inside the SpryValidaionRadio.js file:

// check isRequired
if (this.isRequired && (nochecked == 0 || required != 0))
{
this.addClassName(this.element, this.requiredClass);
this.addClassName(this.additionalError, this.requiredClass);
return false;
}
this.addClassName(this.element, this.validClass);
this.addClassName(this.additionalError, this.validClass);
return true;

};
Copy linkTweet thisAlerts:
@spacemocauthorSep 16.2010 — Any idea how to make it work ?
×

Success!

Help @spacemoc 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.28,
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,
)...