ตัวอย่างโค๊ด
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
<script type="text/javascript"> function check_uncheck_all(checkname, field) { for (i = 0; i < checkname.length; i++) { checkname[i].checked = field.checked? true:false } } function validate_frm(group) { // begin function: check form var is_select = false; for ( i = 0; i < group.elements.length; i++) { // start for if (group.elements[i].checked == true) { // start if is_select = true; break; } // end if } // end for if (is_select == false) { // start if alert("Please select at least one entity."); return (false); } // end if if (!confirm("Are you sure ?")) { // start if return (false); } // end if return (true); } // end function: check form </script> <?php //get value from submit if(isset($_POST['id'])){ if(count($_POST['id'])>0){ foreach($_POST['id'] as $index=>$value){ echo $index." => ".$value."<br />"; } } } ?> <form id="selectall" name="selectall" method="post" onsubmit="return validate_frm(this);" > <table> <tr bgcolor="#CCCCCC"> <td> <input name="chk_all" type="checkbox" id="chk_all" onClick="check_uncheck_all(document.selectall.id,this)" /> </td> <td><strong>Value</strong></td> </tr> <?php for($i=0;$i<=20;$i++){ ?> <tr> <td> <input name="id[<?php echo $i; ?>]" class="myCheckbox" type="checkbox" id="id" value="<?php echo $i; ?>" /> </td> <td>#value : <?php echo $i; ?></td> </tr> <?php } ?> <tr> <td colspan="2"><input type="submit" value="submit" ></td> </tr> </table> </form> |