Skip to main content
Inspiring
May 2, 2012
Question

check/uncheck all check boxes

  • May 2, 2012
  • 1 reply
  • 2033 views

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

This topic has been closed for replies.

1 reply

BKBK
Community Expert
Community Expert
May 4, 2012

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.name.toLowerCase() != 'hazard') aa.elements.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>