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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Checkbox - Checking by group

    Hi.

    I have this code HTML:

    <ul>
    <li><a href="javascript:showHidden('L10');">Dir. Serviços</a><INPUT type=CHECKBOX name="checkbox" id="checkboxA1" value="A1" onclick="javascript:group()"></td>
    <ul id="L10" style="display:none;VISIBILITY:hidden;">
    <table>
    <tr>
    <td><li id="DS01">Ana Velosa</li></td>
    <td align="center"><INPUT type=CHECKBOX name="checkbox" id="checkboxA2" value="A2"></td>
    </tr>
    <tr>
    <td><li id="DS02">Carlos Coelho</li></td>
    <td align="center"><INPUT type=CHECKBOX name="checkbox" id="checkboxA3" value="A3"></td>
    </tr>
    </table>
    </ul>
    </li>
    <p>

    <li><a href="javascript:showHidden('L11');">Dir. Turismo</a><INPUT type=CHECKBOX name="checkbox" id="checkboxB1" value="B1" onclick="javascript:group()"></td>
    <ul id="L11" style="display:none;VISIBILITY:hidden;">
    <table>
    <tr>
    <td><li id="DT01">Ana Mendonça</li></td>
    <td align="center"><INPUT type=CHECKBOX name="checkbox" id="checkboxB2" value="B2"></td>
    </tr>
    <tr>
    <td><li id="DT02">João Barnabé</li></td>
    <td align="center"><INPUT type=CHECKBOX name="checkbox" id="checkboxB3" value="B3"></td>
    </tr>
    </table>
    </ul>
    </li>
    <p>
    </ul>

    I need without change de name, only with the id, wen select a checkbox of the <ul>, change all checkboxes in this tag (all the li).

    I try, i try, but only obtain errors.

    Can anyone help me?
    Thanks

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,511
    Thanks
    3
    Thanked 504 Times in 491 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    
    <body>
    <ul>
    <li><a href="javascript:showHidden('L10','checkboxA1');">Dir. Serviços</a><INPUT type=CHECKBOX name="checkbox" id="checkboxA1" value="A1"  onclick="group(this)"></td>
    <ul id="L10" style="display:none;">
    <table>
    <tr>
    <td><li id="DS01">Ana Velosa</li></td>
    <td align="center"><INPUT type=CHECKBOX name="checkbox" id="checkboxA2" value="A2"></td>
    </tr>
    <tr>
    <td><li id="DS02">Carlos Coelho</li></td>
    <td align="center"><INPUT type=CHECKBOX name="checkbox" id="checkboxA3" value="A3"></td>
    </tr>
    </table>
    </ul>
    </li>
    <p>
    
    <li><a href="javascript:showHidden('L11','checkboxB1');">Dir. Turismo</a><INPUT type=CHECKBOX name="checkbox" id="checkboxB1" value="B1" onclick="group(this)"></td>
    <ul id="L11" style="display:none;">
    <table>
    <tr>
    <td><li id="DT01">Ana Mendonça</li></td>
    <td align="center"><INPUT type=CHECKBOX name="checkbox" id="checkboxB2" value="B2"></td>
    </tr>
    <tr>
    <td><li id="DT02">João Barnabé</li></td>
    <td align="center"><INPUT type=CHECKBOX name="checkbox" id="checkboxB3" value="B3"></td>
    </tr>
    </table>
    </ul>
    </li>
    <p>
    </ul>
    <script language="JavaScript" type="text/javascript">
    /*<![CDATA[*/
    
    function showHidden(id,cbid){
     var obj=document.getElementById(id);
     obj.style.display=obj.style.display=='none'?'':'none';
     var cbobj=document.getElementById(cbid);
     if (obj.style.display=='none'){ return; }
     var scbs=obj.getElementsByTagName('INPUT');
     cbobj.ary=[];
     for (var zxc0=0;zxc0<scbs.length;zxc0++){
      if (scbs[zxc0].type=='checkbox'){
       scbs[zxc0].checked=cbobj.checked;
       cbobj.ary.push(scbs[zxc0]);
      }
     }
    }
    
    function  group(obj){
     if (!obj.ary){ return; }
     for (var zxc0=0;zxc0<obj.ary.length;zxc0++){
      obj.ary[zxc0].checked=obj.checked;
     }
    }
    
    /*]]>*/
    </script>
    </body>
    
    </html>
    be sure that all elements are display:''; before submission
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi. Thanks for your replay.

    This don't work like i need.

    A have one page with a link to the popup window with the checkbox. When the popup window open, i select one um checkbox and return to initial page de value os this checkbox to a hidden field.

    If the hidden field have some numbers, i passed than to the popup windows and the checkbox with this value is checked. A do this by:

    function get_check_value()
    //Retorna a string de valores checkados.
    {
    var c_value = ";";
    for (var i=0; i < document.listagem.checkbox.length; i++)
    {
    if (document.listagem.checkbox[i].checked)
    {
    c_value = c_value + document.listagem.checkbox[i].value + ";";
    }
    }
    return c_value;
    }


    function valor(lista)
    //Checka as caixas a partir da lista de valores.
    {
    var elems = lista.split(";");
    for(i in elems) {
    var valor = elems[i];

    if (valor != null && valor.length != 0) {
    var checkboxes = document.forms['listagem'].elements['checkbox'];
    for (j = 0; j < checkboxes.length; j++) {
    var chk = checkboxes[j];
    if (chk.value == valor){
    chk.checked = true;
    }
    }
    }
    }
    }

    This works like i want, than i can't use de name os the checkbox to the new functionality.

    But now i need check all the sub-checkbox when check a main checkbox in real time. But with this code, wen i check the checkbox A2, will check wrong B2.

    This is my problem. I try this, but is wrong, because don't work's:

    function checkGroup()
    {
    var checkboxes = document.forms['listagem'].elements['checkbox'];
    var elemento = document.getElementById('checkbox');
    if ((elemento.id.substring(10,9) == "1") && (elemento.checked) == true) {
    var codigo = elemento.id.substring(9,8)
    for (i=0; i < checkboxes.length; i++) {
    var chk = checkboxes[j];
    if (chk.id.substring(9,8) == codigo) {
    chk.checked = true;
    }
    }
    }
    }

    Thanks for you time and knowledge.
    Pedro


  •  

    Posting Permissions

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