...

View Full Version : 1 radio button group imitating other.



deki
07-17-2009, 01:52 PM
I have 2 radio button groups (A & B) in a form. How can I get a button in group B to automatically be checked based on a button in group A being checked?

I tried with the script beneath, but with while($row = mysql_fetch_array($result)) php generated form in a HTML table, only the top row in group B changes no mater what row in group A is checked.

Can anybody help me with this? Thanx!


<script language="javascript">
function getObject(obj){if(document.getElementById){return document.getElementById(obj);}else{if(document.all){return document.all[obj];}}}
function radioBtnGroupChanged(obj){
switch(obj.id) {
case "rbA1":
getObject('rbB2').checked = true;
break;
case "rbA2":
getObject('rbB1').checked = true;
break;
}
}
</script>


<input type="radio" id="rbA1" name="rbA" onclick="radioBtnGroupChanged(this);" /><br />
<input type="radio" id="rbA2" name="rbA" onclick="radioBtnGroupChanged(this);" />
<br />
<br />
<br />
<input type="radio" id="rbB1" name="rbB" /><br />
<input type="radio" id="rbB2" name="rbB" />

vwphillips
07-17-2009, 04:31 PM
<!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" xml:lang="en" lang="en">

<head>
<title></title>
</head>

<body>
<script language="javascript">
function radioBtnGroupChanged(obj,to){
var frm=obj.form;
for (var z0=0;z0<frm[obj.name].length;z0++){
if (frm[to][z0]) frm[to][z0].checked=frm[obj.name][z0].checked;
}

}
</script>

<form>
<input type="radio" id="rbA1" name="rbA" onclick="radioBtnGroupChanged(this,'rbB');" /><br />
<input type="radio" id="rbA2" name="rbA" onclick="radioBtnGroupChanged(this,'rbB');" />
<br />
<br />
<br />
<input type="radio" id="rbB1" name="rbB" /><br />
<input type="radio" id="rbB2" name="rbB" />
</form>
</body>

</html>

deki
07-17-2009, 04:49 PM
You rock! This works perfectly! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum