3

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;
 }
}
HashimR
  • 3,803
  • 8
  • 32
  • 49
subodh
  • 6,136
  • 12
  • 51
  • 73

2 Answers2

5

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

HashimR
  • 3,803
  • 8
  • 32
  • 49
  • Thanks, Can u give me any example of submitting collection as a form in struts1.3. Or can you provide me the solution of http://stackoverflow.com/questions/7971017/in-struts1-3-how-handling-multiple-formbean-property-to-action – subodh Nov 14 '11 at 05:02
0

Only one HTML element in a document may have a given ID. Your page is thus invalid. BTW, that's why the method is name getElementById (singular) and not getElementsById (plural).

Use document.getElementsByName("ExporterForm") and iterate through the returned list to check every checkbox of the list.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255