Multiple Checkbox Help Needed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ralph Freshour

    Multiple Checkbox Help Needed

    I have a function that I call to check or uncheck all checkboxes on a
    form - I use a 'master' checkbox to do this much like hotmail has to
    check all mail messages - the code works fine if I name my checkboxes
    like this:
    chk1
    chk1
    chk1

    But I need to name them with an array for deletion purposes which is
    already coded and working - I need to name them like this:
    chk[0]
    chk[1]
    chk[2]

    I can't get the check/uncheck function to work with array checkbox
    names - at the bottom of this I show my main checkbox I use to check
    or uncheck all the others checkboxes named chk1 - but how do I pass
    the name of the array checkboxes???


    <!-- Hide javascript code
    function check_checkboxe s(pObj, pFlag)
    {
    if (pObj.length) {
    for (var iCount=0; iCount<pObj.len gth; iCount++)
    pObj [ iCount ].checked = pFlag;
    }
    else {
    pObj.checked = pFlag;
    }
    }
    // stop hiding javascript -->
    </SCRIPT>

    <INPUT TYPE="checkbox" NAME="frm_check _all"
    onClick="check_ checkboxes(docu ment.pmsgs_form .chk1,
    frm_check_all.c hecked)">Check/UnCheck All</TD>
  • Janwillem Borleffs

    #2
    Re: Multiple Checkbox Help Needed


    "Ralph Freshour" <ralph@primemai l.com> schreef in bericht
    news:dpugovcuva gt711666msaej8u skdj55puf@4ax.c om...[color=blue]
    >
    > But I need to name them with an array for deletion purposes which is
    > already coded and working - I need to name them like this:
    > chk[0]
    > chk[1]
    > chk[2]
    >
    > I can't get the check/uncheck function to work with array checkbox
    > names - at the bottom of this I show my main checkbox I use to check
    > or uncheck all the others checkboxes named chk1 - but how do I pass
    > the name of the array checkboxes???
    >[/color]

    <script type="text/javascript">
    function check_checkboxe s(pForm, pObj, pFlag) {
    for (var iCount=0;;iCoun t++) {
    if (!pForm.element s[pObj + iCount]) break;
    pForm.elements[pObj + iCount ].checked = pFlag;
    }
    }
    </script>

    <form>
    <input type="checkbox" name="chk0"><br />
    <input type="checkbox" name="chk1"><br />
    <input type="checkbox" name="chk2"><br />
    <input type="checkbox" name="frm_check _all"
    onclick="check_ checkboxes(form ,'chk',checked) ">Check/UnCheck All
    </form>


    JW



    Comment

    • Janwillem Borleffs

      #3
      Re: Multiple Checkbox Help Needed


      "Janwillem Borleffs" <jw@jwscripts.c om> schreef in bericht
      news:3f890068$0 $64200$1b62eedf @news.euronet.n l...[color=blue][color=green]
      > >
      > > But I need to name them with an array for deletion purposes which is
      > > already coded and working - I need to name them like this:
      > > chk[0]
      > > chk[1]
      > > chk[2]
      > >[/color][/color]

      Just realised that my previous solution did not work with PHP-array style
      element names, the following does:

      <script type="text/javascript">
      function check_checkboxe s(pForm, pObj, pFlag) {
      var elem;
      for (var iCount=0;;iCoun t++) {
      elem = pObj + '[' + iCount + ']';
      if (!pForm.element s[elem]) break;
      pForm.elements[elem].checked = pFlag;
      }
      }
      </script>

      <form>
      <input type="checkbox" name="chk[0]"><br />
      <input type="checkbox" name="chk[1]"><br />
      <input type="checkbox" name="chk[2]"><br />
      <input type="checkbox" name="frm_check _all"
      onclick="check_ checkboxes(form ,'chk',checked) ">Check/UnCheck All
      </form>

      Also, have a look at the FAQ entry regarding this subject:




      JW



      Comment

      Working...