Skip navigation
Currently Being Moderated

check/uncheck all check boxes

May 2, 2012 6:02 AM

I  have the code for select and de-select all check boxes at the same time.  It worked fine for all check boxes inside the cfloop but the other check box outside the cfloop is harzard is also messup. Right now, when i click on the check box for Select / Deselect All check box, the check box for for harzard is also check/uncheck and I don't want it to be checked but don't know how, can you help?.

 

 

<script language="javascript" >

checked=false;

function checkedAll (frm) {

    var aa= document.getElementById('frm');

     if (checked == false)

          {

           checked = true

          }

        else

          {

          checked = false

          }

    for (var i =0; i < aa.elements.length; i++)

    {

     aa.elements[i].checked = checked;

    }

      }

</script>

<cfform action="insert.cfm" name="frm" id="frm" method="post">

<input type='checkbox' name='checkall' onclick='checkedAll(frm);'>  Select / Deselect All

<cfloop query="variables.qlist">

<cfinput type="checkbox" id="instanaceid" name="instanaceid" value="#id#">#shortname#

</cfloop>

<br>

<cfinput type="checkbox" name="hazard" id="hazard" value="1">

<cfinput type="submit" name="submit" id="submit" value="Save">

</cfform>

 

Thanks

 

KT

 
Replies
  • Currently Being Moderated
    May 4, 2012 2:43 PM   in reply to kt03

    Do you mean you want the Select All / Deselect All event to apply to all the checkboxes except the Hazard checkbox? If so, then modify the script to something like

     

    <script type="text/javascript" language="javascript" >

    var checked=false;

    function checkedAll (frm) {

        var aa = document.getElementById('frm');

         if (checked == false)

              {

               checked = true

              }

            else

              {

              checked = false

              }

        for (var i = 0; i < aa.elements.length; i++)

        {

            if(aa.elements[i].name.toLowerCase() != 'hazard') aa.elements[i].checked = checked;

        }

    }

    </script>

     

    <cfform name="frm" id="frm" method="post">

    <input type='checkbox' name='checkall' onclick='checkedAll(frm);'>  Select All / Deselect All

    <cfloop query="qlist">

    <cfinput type="checkbox" id="instanaceid" name="instanaceid" value="#id#"><cfoutput>#shortname#</cfoutput>

    </cfloop>

    <br>

    <cfinput type="checkbox" name="hazard" id="hazard" value="1">Hazard

    <br>

    <cfinput type="submit" name="submit" id="submit" value="Save">

    </cfform>

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points