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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Location
    UK
    Posts
    207
    Thanks
    6
    Thanked 2 Times in 2 Posts

    checkbox trouble

    Hi

    I'm having trouble getting a set of checkboxes to hide/show some hidden info...

    if there is more than 1 checkbox ticked, nothing will turn off again??!!!!

    Any ideas what i need to do to cure this problem

    Here's the source code

    Thanks

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    you gave some of your checkboxes the same name. Do you really need those names to be like that? You might get trouble when sending to the server. Can't u use something like this?

    <input type="checkbox" name="group1_1" onclick="rev(0)">a) group1<br>
    <input type="checkbox" name="group1_2" onclick="rev(0)">b) group1<br>
    <input type="checkbox" name="group1_3" onclick="rev(0)">c) group1<br><br>

    <input type="checkbox" name="group2_1" onclick="rev(1)">a) group2<br>
    <input type="checkbox" name="group2_2" onclick="rev(1)">b) group2<br>
    <input type="checkbox" name="group2_3" onclick="rev(1)">c) group2<br><br>

    <input type="checkbox" name="group3_1" onclick="rev(2)">a) group3<br>
    <input type="checkbox" name="group3_2" onclick="rev(2)">b) group3<br>

    <input type="checkbox" checked name="group3_3" onclick="rev(2)">c) group3<br><br>

    If so I might rebuild your code
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Regular Coder
    Join Date
    Dec 2005
    Location
    UK
    Posts
    207
    Thanks
    6
    Thanked 2 Times in 2 Posts
    sorry, yes, i had changed the names once... i must have reverted back to an old version though.

    I've updated the file now... if you could help me with my code, that would be great.

    thanks

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/javascript">
    
    function rev(){
    var c = document.getElementsByTagName('input');
    var j=1;
    while(document.getElementById('group'+j+'_d')){
    document.getElementById('group'+j+'_d').style.visibility='hidden';
    j++
    }
    for(var i=0;i<c.length;i++){
    c[i].checked?document.getElementById('group'+c[i].name.match(/\d{1}/)+'_d').style.visibility='visible':null
    }
    }
    onload=rev;
    </script>
    
    </head>
    <body>
    <div id="group1_d" style="visibility:hidden">Revealed from group 1</div>
    <div id="group2_d" style="visibility:hidden">Revealed from group 2</div>
    <div id="group3_d" style="visibility:hidden">Revealed from group 3</div>
    <input type="checkbox" name="group1_1" onclick="rev()">a) group1<br>
    <input type="checkbox" name="group1_2" onclick="rev()">b) group1<br>
    <input type="checkbox" name="group1_3" onclick="rev()">c) group1<br><br>
    
    <input type="checkbox" name="group2_1" onclick="rev()">a) group2<br>
    <input type="checkbox" name="group2_2" onclick="rev()">b) group2<br>
    <input type="checkbox" name="group2_3" onclick="rev()">c) group2<br><br>
    
    <input type="checkbox" name="group3_1" onclick="rev()">a) group3<br>
    <input type="checkbox" name="group3_2" onclick="rev()">b) group3<br>
    <input type="checkbox" name="group3_3" checked onclick="rev()">c) group3<br><br>
    
    </body>
    </html>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Regular Coder
    Join Date
    Dec 2005
    Location
    UK
    Posts
    207
    Thanks
    6
    Thanked 2 Times in 2 Posts
    thats perfect.... thanks!


  •  

    Posting Permissions

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