Radio Button Rulesets

[Total: 0    Average: 0/5]

This shows how to have radio select buttons have rulese for what can be selected together.

Body Code:

<script>
var RULE_SET = new Array();
    RULE_SET[1]=new Array(2,3,4); /* if 1 clicked - turn off 2,3,4 */
	RULE_SET[2]=new Array(1,4);   /* if 2 clicked - turn off 1,4   */
	RULE_SET[3]=new Array(1,2);   /* if 3 clicked - turn off 1,2   */
	RULE_SET[4]=new Array(1,2,3); /* if 4 clicked - turn off 1,2,3 */

function itemClicked(_v)
{
  if(eval("document.exf1.r"+_v+".checked==false"))
  {
    eval("document.exf1.r"+_v+".checked=false");
  }
  else
  {
    for(var _i=0;_i<RULE_SET[_v].length;_i++)
	{
      if(eval("document.exf1.r"+RULE_SET[_v][_i]+".checked"))
      {
        eval("document.exf1.r"+RULE_SET[_v][_i]+".checked=false");
      }
	}
  }
  return true; /* kill the event handler */
}

function showRuleSet()
{
  var _B ="";
      _B+="<HR><BR><H3>RULESET</H3>";
	  for(var _i=1;_i<=4;_i++)
	  {
	    _B+="If "+_i+" clicked - turn off ";
		for(var _j=0;_j<RULE_SET[_i].length;_j++)
		{
		   if(_j!=0)
		   {
		     _B+=",";
		   }
		  _B+=RULE_SET[_i][_j];
		}
		_B+="<BR>";
	  }
	  _B+="<HR>";
  document.write(_B);
}
showRuleSet(); /* comment this out to not see the ruleset */
</script>

<form name=exf1>
<INPUT name=r1 type=radio value=Charity_profile onclick="return itemClicked(1)">Item 1<BR>
<INPUT name=r2 type=radio value=lost_found      onclick="return itemClicked(2)">Item 2<BR>
<INPUT name=r3 type=radio value=fun_section     onclick="return itemClicked(3)">Item 3<BR>
<INPUT name=r4 type=radio value=contacts        onclick="return itemClicked(4)">Item 4<BR>
</form>

Times Viewed: 1

Leave a Reply

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