Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macintosh Allow One Check box checked..

    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??

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Posts
    168
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Here is one possibility :

    <html>
    <head>
    <title>Checkboxes</title>
    <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)
    continue;
    f.elements[i].checked=false;
    }
    }

    </script>
    </head>

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

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    Kansas, USA
    Posts
    487
    Thanks
    0
    Thanked 54 Times in 53 Posts
    Why not use a radiobutton group for this? Its natural behavior is exactly as you described, no javascript required.
    Code:
    <form>
    <fieldset><legend>group1</legend>
    <input type="radio" name="group1" value="1">
    <input type="radio" name="group1" value="2">
    <input type="radio" name="group1" value="3"></fieldset>
    <fieldset><legend>group2</legend>
    <input type="radio" name="group2" value="1">
    <input type="radio" name="group2" value="2">
    <input type="radio" name="group2" value="3"></fieldset>
    </form>

  • #4
    New Coder
    Join Date
    Oct 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    rs.Movefirst
    i = 1
    while not rs.eof
    %>
    <tr>
    <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>
    </tr>
    <%
    i = i + 1
    rs.movenext
    wend
    %>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •