title: How to auto check all checkboxes with same name?
body: <p>I have used checkboxes for checking the mails in my mailing system which is developed in Java.</p>
  
  <p>I want to check all the checkboxes on the click of upper checkbox, but the problem is there that checkboxes are displayed in the the loop according to number of mails retrieved.</p>
  
  <p>Please help me where should i put the javascript code to solve this problem.</p>
  
  <p>The loop code of inbox is given below:</p>
  
  <pre><code>&lt;tr &gt;
          &lt;% for(int i=0;i&lt;messageList.size();i++) { message = (Message)messageList.get(i);%&gt;
          &lt;td width="10%" height="33" align="left"   valign="top" bgcolor="#EEE" &gt;
          &lt;!--This link display the full message--&gt;
  
  
          &lt;input name="Mark_Mail" id="mark_mail" onclick="myfunction(this);" type="checkbox" value="&lt;%=message.getMailId()%&gt;" width="50" height="30" align="top" &gt;
          &lt;span id="space1" style="padding:2px"&gt;&lt;/span&gt;
  
          &lt;!--Check all the Checkboxes--&gt;
          &lt;script type="text/javascript"&gt;
          function checkAll()
          {
              document.getElementById('mark_mail').checked = "true";
          }
  
          &lt;/script&gt;
  
          &lt;img  src="Images/UnStarred.jpg" height="15" border="0"  id="image1" onclick="swapImage()" /&gt;
          &lt;span id="space1" style="padding:2px"&gt;&lt;/span&gt;
          &lt;/td&gt;
          &lt;td width="90%" height="33" align="left" colspan="7"  valign="bottom" bgcolor="#EEE" &gt;
          &lt;!--This link display the full message--&gt;
          &lt;a  id="link" href="viewMail.jsp?mailId=&lt;%=message.getMailId()%&gt;&amp;isAttach=&lt;%=message.getAttachmentFlag()%&gt;"&gt;
          &lt;!--Display Sender Address--&gt;
          &lt;font color="#000000" size="1"&gt;&lt;strong&gt;&lt;%=message.getSenderAddress()%&gt;&lt;/strong&gt;&lt;/font&gt;
          &lt;span id="space1" style="padding:6px"&gt;&lt;/span&gt;
  
          &lt;!--For Display Message Subject--&gt;
          &lt;font color="#000000" size="1"&gt;&lt;strong&gt;&lt;%=message.getSubject()%&gt;&lt;/strong&gt;&lt;/font&gt;
          &lt;span id="space1" style="padding:6px"&gt;&lt;/span&gt;
  
          &lt;!--For Display Attachment Image--&gt;
          &lt;%if(message.getAttachmentFlag().equals("1")){%&gt;&lt;input type="hidden" name="filename" id="filename" value="&lt;%=message.getFileName()%&gt;" /&gt;&lt;input type="hidden" name="filesize" id="filesize" value="&lt;%=message.getFileSize()%&gt; /&gt;&lt;img src ="Images/attachment.jpg" style="bgcolor: #EEE" /&gt;&lt;%}else{%&gt;&lt;span style="padding-left:12px" &gt;&lt;/span&gt;&lt;%}%&gt;
          &lt;span id="space1" style="padding:6px"&gt;&lt;/span&gt;
  
          &lt;!--For Display Time and Date of messaging--&gt;
          &lt;font color="#000000" size="1"&gt;&lt;strong&gt;&lt;%=message.getTimestamp()%&gt;&lt;span style="padding-left:5px"&gt;&lt;/span&gt;&lt;%=message.getDate()%&gt;&lt;input type="hidden" name="label" value="&lt;%=message.getLabel()%&gt;"&gt;&lt;/strong&gt;&lt;/font&gt;
          &lt;/a&gt;&lt;/td&gt;
          &lt;/tr&gt;&lt;% } %&gt;
  </code></pre>