Radio Selector Determinor

[Total: 0    Average: 0/5]

This example will go through all radio objects and determine which ones are selected.

Body Code:

Choose what you will. Then I'll tell you what you have selected.
<BR>I'll also tell you if you select R1:C.
<form name=exf1>
R1:
A <input type=radio name=r1 value="R1_A">
B <input type=radio name=r1 value="R1_B">
C <input type=radio name=r1 value="R1_C">
D <input type=radio name=r1 value="R1_D">
<BR>
R2:
A <input type=radio name=r2 value="R2_A">
B <input type=radio name=r2 value="R2_B">
C <input type=radio name=r2 value="R2_C">
D <input type=radio name=r2 value="R2_D">
<BR>
R3:
A <input type=radio name=r3 value="R3_A">
B <input type=radio name=r3 value="R3_B">
C <input type=radio name=r3 value="R3_C">
D <input type=radio name=r3 value="R3_D">
<BR><BR>
<input type=button value="Tell me what is selected." onclick="doIt()">
</form>
<script>
function doIt()
{
  var _f=document.exf1;
  var _m="";
  var _obj=null;

  _obj=_f.r1;
  for(var i=0;i<_obj.length;i++)
    if(_obj[i].checked)
	  _m+="Selected: "+_obj[i].name+"="+_obj[i].value+"n";

  _obj=_f.r2;
  for(var i=0;i<_obj.length;i++)
    if(_obj[i].checked)
	  _m+="Selected: "+_obj[i].name+"="+_obj[i].value+"n";

  _obj=_f.r3;
  for(var i=0;i<_obj.length;i++)
    if(_obj[i].checked)
	  _m+="Selected: "+_obj[i].name+"="+_obj[i].value+"n";

  alert(_m);
  
  if(_f.r1[2].checked) alert("You have selected R1_C");
}
</script>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *