Checked all CheckBox of a Jsp page

11,170

You can use getElementsByTagName method of Javascript.

This code might be of your help!

function checkAll() 
{
    //alert("Check all the checkboxes..."); 
    var allRows = document.getElementsByTagName("input");
    for (var i=0; i < allRows.length; i++) {
        if (allRows[i].type == 'checkbox') 
        {
            allRows[i].checked = true;
        }
    }

}

You can call this function from your html checkbox.

Edit:

these links might help you.

javascript-check-one-check-all-checkbox

Javascript Function to Check or Uncheck all Checkboxes

Another Link

Share:
11,170
subodh
Author by

subodh

OCJP 6 certified SSCCE What kind of questions can I ask here? How does accepting an answer work in SO?

Updated on June 04, 2022

Comments

  • subodh
    subodh almost 2 years

    I am using Struts1.3, and in this Jsp page dynamically generate check boxes depends on the data available in Database. my code which is generate check boxes is as follow

    <table width="850" border="0" align="left" cellpadding="2" cellspacing="0">
       <tr>
        <td width="100" align="center" bgcolor="#F3F3F3"><label>
        <html:checkbox name="ExporterForm" value="<%=authlist.get(i).getAuthorityid()%>" property="exportauthority" styleId="checkbox99"  />
        </label></td>
        <td align="center" class="text_exp" ><%=authlist.get(i).getAuthorityname()%></td>
       </tr>
     </table>
    

    I have one more check Box(selectAll), and query is, I want to mark checked all while selection of selectAll CheckBox.

    and my code is for checked all check box is given below but it's select only one and need to select all please show me the path to achieve it.

    function selectAllAuthorites()
    {
     var selectAll=document.getElementById("checkbox101")
     if(selectAll.checked==true)
     {
         document.getElementById("checkbox99").checked=true;
     }
    }
    
  • subodh
    subodh over 12 years
    Thanks, Can u give me any example of submitting collection as a form in struts1.3. Or can you provide me the solution of stackoverflow.com/questions/7971017/…