<html> <head> <title>ThaiCreate.Com Tutorial</title> </head> <body> <script language="JavaScript"> function ShowAll(vol) { var i=0; for(i=0;i<=document.frmMain.txtName.length;i++) { alert(document.frmMain.txtName[i].value); } } </script> <form name="frmMain" action="get_element_with_array2.php" method="post" OnSubmit="return onDelete();"> <input type="text" name="txtName[]" id="txtName" value="Mr.Weerachai Nukitram"><br> <input type="text" name="txtName[]" id="txtName" value="Mr.Surachai Sirisart"><br> <input type="text" name="txtName[]" id="txtName" value="Mr.Adisorn Bunsong"><br> <input type="button" name="btnCheck" value="Show" OnClick="ShowAll();"> </form> </body> </html>
CREATE TABLE `customer` ( `CustomerID` varchar(4) NOT NULL, `Name` varchar(50) NOT NULL, `Email` varchar(50) NOT NULL, `CountryCode` varchar(2) NOT NULL, `Budget` double NOT NULL, `Used` double NOT NULL, PRIMARY KEY (`CustomerID`), FULLTEXT KEY `Name` (`Name`,`Email`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- -- Dumping data for table `customer` -- INSERT INTO `customer` VALUES ('C001', 'Win Weerachai', '[email protected]', 'TH', 1000000, 600000); INSERT INTO `customer` VALUES ('C002', 'John Smith', '[email protected]', 'EN', 2000000, 800000); INSERT INTO `customer` VALUES ('C003', 'Jame Born', '[email protected]', 'US', 3000000, 600000); INSERT INTO `customer` VALUES ('C004', 'Chalee Angel', '[email protected]', 'US', 4000000, 100000);
<html> <head> <title>ThaiCreate.Com Tutorial</title> </head> <body> <script language="JavaScript"> function ClickCheckAll(vol) { var i=0; for(i=0;i<=document.frmMain.chkDel.length-1;i++) { if(vol.checked == true) { document.frmMain.chkDel[i].checked=true; } else { document.frmMain.chkDel[i].checked=false; } } } </script> <form name="frmMain" action="get_element_with_array2.php" method="post" OnSubmit="return onDelete();"> <? $objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database"); $objDB = mysql_select_db("mydatabase"); $strSQL = "SELECT * FROM customer"; $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); ?> <table width="600" border="1"> <tr> <th width="91"> <div align="center">CustomerID </div></th> <th width="98"> <div align="center">Name </div></th> <th width="198"> <div align="center">Email </div></th> <th width="97"> <div align="center">CountryCode </div></th> <th width="59"> <div align="center">Budget </div></th> <th width="71"> <div align="center">Used </div></th> <th width="30"> <div align="center"> <input name="CheckAll" type="checkbox" id="CheckAll" value="Y" onClick="ClickCheckAll(this);"> </div></th> </tr> <? $i = 0; while($objResult = mysql_fetch_array($objQuery)) { $i++; ?> <tr> <td><div align="center"><?php echo $objResult["CustomerID"];?></div></td> <td><?php echo $objResult["Name"];?></td> <td><?php echo $objResult["Email"];?></td> <td><div align="center"><?php echo $objResult["CountryCode"];?></div></td> <td align="right"><?php echo $objResult["Budget"];?></td> <td align="right"><?php echo $objResult["Used"];?></td> <td align="center"><input type="checkbox" name="chkDel[]" id="chkDel" value="<?php echo $objResult["CustomerID"];?>"></td> </tr> <? } ?> </table> <? mysql_close($objConnect); ?> <input type="submit" name="btnSubmit" value="Submit"> </form> </body> </html>
<html> <head> <title>ThaiCreate.Com Tutorial</title> </head> <body> <? for($i=0;$i<=count($_POST["chkDel"]);$i++) { echo $_POST["chkDel"][$i]."<br>"; } ?> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท