View Full Version : Allow One Check box checked..

11-06-2004, 09:15 AM
i have multiple check box but i only want ONE check box is checked when the onclick method apply, the rest unchecked, while all the check box is same name....is there any solution??

Puffin the Erb
11-06-2004, 01:05 PM
Here is one possibility :

<script type="text/javascript">
function resetChecks(currentCheckBox)
f = document.forms[0];

for(i=0; i<f.elements.length;i++)
if(f.elements[i].type!="checkbox" || i==currentCheckBox)


<input type="checkbox" onClick="resetChecks(0)" name="choice">
<input type="checkbox" onClick="resetChecks(1)" name="choice">
<input type="checkbox" onClick="resetChecks(2)" name="choice">

11-06-2004, 06:21 PM
Why not use a radiobutton group for this? Its natural behavior is exactly as you described, no javascript required.
<input type="radio" name="group1" value="1">
<input type="radio" name="group1" value="2">
<input type="radio" name="group1" value="3"></fieldset>
<input type="radio" name="group2" value="1">
<input type="radio" name="group2" value="2">
<input type="radio" name="group2" value="3"></fieldset>

11-08-2004, 02:55 AM
Actually i am trying to do in this way, everytime, the system will loop thru the database and get the matching data, then place in table, so, i wouldn't know how many checkbox in a time. Once i click on either one of the checkbox, it will redirect to the respective page.
if rs.bof <> true and rs.eof <> true then
i = 1
while not rs.eof
<td width="5%" height="17" background="../../../images/loan/bg1.gif">
<input type="checkbox" name="chkbox" value="ON"></td>
<td width="12%" height="17"><%=rs("acctno")%></td>
<td width="1%" height="17"><%=rs("cifno")%></td>
<td width="30%" height="17"><%=rs("cfsnme")%></td>
<td width="15%" height="17">&nbsp;</td>
i = i + 1