|
|
|
Dynamic Textbox ช่วยดูโค้ดให้ผมหน่อยครับ...ว่าผิดตรงไหนครับ!!! ^_^ |
|
|
|
|
|
|
|
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com JavaScript Add/Remove Element</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<script language="javascript">
function CreateNewRow()
{
var intLine = parseInt(document.frmMain.hdnMaxLine.value);
intLine++;
var theTable = document.all.tbExp
var newRow = theTable.insertRow(theTable.rows.length)
newRow.id = newRow.uniqueID
var item1 = 1
var newCell
//*** Column 1 ***//
newCell = newRow.insertCell(0)
newCell.id = newCell.uniqueID
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column1_"+intLine+"\" VALUE=\"\"></center>"
//*** Column 2 ***//
newCell = newRow.insertCell(1)
newCell.id = newCell.uniqueID
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column2_"+intLine+"\" VALUE=\"\"></center>"
//*** Column 3 ***//
newCell = newRow.insertCell(2)
newCell.id = newCell.uniqueID
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column3_"+intLine+"\" VALUE=\"\"></center>"
//*** Column 4 ***//
newCell = newRow.insertCell(3)
newCell.id = newCell.uniqueID
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column4_"+intLine+"\" VALUE=\"\"></center>"
//*** Column 5 ***//
newCell = newRow.insertCell(4)
newCell.id = newCell.uniqueID
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column5_"+intLine+"\" VALUE=\"\"></center>"
document.frmMain.hdnMaxLine.value = intLine;
}
function RemoveRow()
{
intLine = parseInt(document.frmMain.hdnMaxLine.value);
if(parseInt(intLine) > 0)
{
theTable = (document.all) ? document.all.tbExp :
document.getElementById("tbExp")
theTableBody = theTable.tBodies[0];
theTableBody.deleteRow(intLine);
intLine--;
document.frmMain.hdnMaxLine.value = intLine;
}
}
</script>
<body>
<form name="frmMain" method="post" action="save.php">
<table width="445" border="1" id="tbExp">
<tr>
<td><div align="center">Column 1 </div></td>
<td><div align="center">Column 2 </div></td>
<td><div align="center">Column 3 </div></td>
<td><div align="center">Column 4 </div></td>
<td><div align="center">Column 5 </div></td>
</tr>
</table>
<input type="hidden" name="hdnMaxLine" value="0">
<input name="btnAdd" type="button" id="btnAdd" value="+" onClick="CreateNewRow();">
<input name="btnDel" type="button" id="btnDel" value="-" onClick="RemoveRow();">
<label> <br>
<br>
<input name="save" type="submit" id="save" value="save">
</label></form>
</body>
</html>
คำสั่งบันทึก
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<?
mysql_connect("localhost","root","root") or die (mysql_error());
mysql_select_db("mydatabase");
for($i=1;$i<=(int)($_POST["hdnMaxLine"]);$i++)
{
$strSQL = "INSERT INTO customer ";
$strSQL .="(1,2,3,4,5) VALUES ('".$_POST["Column1_".$i]."','".$_POST["Column2_".$i]."','".$_POST["Column3_".$i]."','".$_POST["Column4_".$i]."','".$_POST["Column5_".$i]."')";
mysql_query($strSQL);
}
mysql_close();
?>
</body>
</html>
Tag : PHP, MySQL, HTML/CSS, JavaScript, Ajax, jQuery
|
|
|
|
|
|
Date :
2014-01-26 20:27:13 |
By :
aunza |
View :
914 |
Reply :
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มันผิดยังไงครับ ^___^
|
|
|
|
|
Date :
2014-01-26 22:24:21 |
By :
itpcc |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mysql_query($strSQL) or die(mysql_error());
|
|
|
|
|
Date :
2014-01-26 23:23:49 |
By :
arm8957 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แคปภาพ ตาราง customer มาให้ดูหน่อยคับ
|
|
|
|
|
Date :
2014-01-27 00:24:09 |
By :
tomrambo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
for($i=1;$i<=(int)($_POST["hdnMaxLine"]);$i++)
{
$strSQL = "INSERT INTO customer ";
$strSQL .="(`1`, `2`, `3`, `4`, `5`) VALUES ('".$_POST["Column1_".$i]."','".$_POST["Column2_".$i]."','".$_POST["Column3_".$i]."','".$_POST["Column4_".$i]."','".$_POST["Column5_".$i]."')";
ลองดูคับ ไม่ได้ค่อยว่าอีกที
|
|
|
|
|
Date :
2014-01-27 10:59:51 |
By :
tomrambo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|