469,307 Members | 1,821 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,307 developers. It's quick & easy.

Check box validation

18
hi all,
i am having a page where there are some checkboxes in it. i cant give exact number because i am getting that from database. so now if the user didnt check atleast one check box i need to get a popup. so can any one help me please..its urgent..
Thank u..
Expand|Select|Wrap|Line Numbers
  1. <table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 500px" bordercolor="red">
  2.     <tr>
  3.         <th></th>
  4.         <th style="color: navy;">Userid</th>
  5.         <th style="color: navy;">Username</th>
  6.  
  7.     </tr>
  8.     <?php
  9.     $sno=1;
  10.     while($row=mysql_fetch_array($result2, MYSQL_ASSOC)){
  11.     ?>
  12.      <tr>
  13. <td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['userid']; ?>"></td>
  14. <td><? echo $row['userid']; ?></td>
  15. <td><? echo $row['username'];?></td>
  16. </tr>
  17. <?php
  18.     $sno=$sno+1;
  19. }
  20. ?>
  21.     </table>
Jun 3 '10 #1
1 1001
Dormilich
8,651 Expert Mod 8TB
a popup is a client-side action, thus PHP cant be (directly) involved.

to check whether no checkbox was selected, loop over all checkboxes and test for the .checked property.

Expand|Select|Wrap|Line Numbers
  1. // returns true if at least one box is checked, otherwise false
  2. function checkBox()
  3. {
  4.     var i, list = document.forms[0]["checkbox[]"];
  5.     for (i = list.length; i--;) {
  6.         if (list[i].checked) {
  7.             return true;
  8.         }
  9.     }
  10.     return false;
  11. }
Jun 3 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

21 posts views Thread by Stefan Richter | last post: by
1 post views Thread by betterdie | last post: by
2 posts views Thread by Hawksey | last post: by
5 posts views Thread by rodchar | last post: by
6 posts views Thread by serge calderara | last post: by
11 posts views Thread by Rik | last post: by
1 post views Thread by John Chan | last post: by
6 posts views Thread by Jon Paal | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.