Only One Radio Button

[Total: 0    Average: 0/5]

This script allows only one radio button item to be selected.

Body Code:

<table border="0" cellpadding="0" cellspacing="0" align="center" valign="top" width="100%">
<tr>
<td align="center">
<table cellpadding="5" width='100%'>
<tr>
<td>
<form name="chooseOne">
<script>
function chooseOnlyOne(i)
{
  var _x=new Array('k','t','d','sm','a','c','h','i','b');
  for(var j=0;j<=8;j++)
  {
    if(j != i)
    {
      eval("document.chooseOne."+_x[j]+"[0].checked=false");
      eval("document.chooseOne."+_x[j]+"[1].checked=true");
    }
  }
}
</script>

<table border="0" align="center">

<tr>
<td>Item 0</td>
<td><input type="radio" name="k" value="1" checked onclick="chooseOnlyOne(0)"></td>
<td><input type="radio" name="k" value="0"></td>
</tr>

<tr>
<td>Item 1</td>
<td><input type="radio" name="t" value="1" onclick="chooseOnlyOne(1)"></td>
<td><input type="radio" name="t" value="0" checked></td>
</tr>

<tr>
<td>Item 2</td>
<td><input type="radio" name="d" value="1"  onclick="chooseOnlyOne(2)"></td>
<td><input type="radio" name="d" value="0" checked></td>
</tr>

<tr>
<td>Item 3</td>
<td><input type="radio" name="sm" value="1" onclick="chooseOnlyOne(3)"></td>
<td><input type="radio" name="sm" value="0" checked></td>
</tr>

<tr>
<td>Item 4</td>
<td><input type="radio" name="a" value="1" onclick="chooseOnlyOne(4)"></td>
<td><input type="radio" name="a" value="0" checked></td>
</tr>

<tr>
<td>Item 5</td>
<td><input type="radio" name="c" value="1"  onclick="chooseOnlyOne(5)"></td>
<td><input type="radio" name="c" value="0" checked></td>
</tr>

<tr>
<td>Item 6</td>
<td><input type="radio" name="h" value="1"  onclick="chooseOnlyOne(6)"></td>
<td><input type="radio" name="h" value="0" checked></td>
</tr>

<tr>
<td>Item 7</td>
<td><input type="radio" name="i" value="1" onclick="chooseOnlyOne(7)"></td>
<td><input type="radio" name="i" value="0" checked></td>
</tr>

<tr>
<td>Item 8</td>
<td><input type="radio" name="b" value="1" onclick="chooseOnlyOne(8)"></td>
<td><input type="radio" name="b" value="0" checked></td>
</tr>
</table>

</form>

</td>
</tr>
</table>
</td>
</tr>
</table>

Times Viewed: 2

Leave a Reply

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