|
|
|
จากโค้ดในตัวอย่างที่ Admin ได้ทำเอาไว้ ผมสามารถเพิ่ม ปุ่ม ลบ เฉพาะ row นั้นๆได้ไหมครับ |
|
|
|
|
|
|
|
ไปใช้ jquery จะง่ายกว่านี้ 555 อันนี้ผมยอมไม่เก่ง javascript
|
|
|
|
|
Date :
2016-02-03 01:23:29 |
By :
progamer2000 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมก็พึ่งเริ่ม ศึกษา ตอนแรกก็ Java script ยิ่งศึกษายิ่ง งง แต่พอเจอ Jquery สบายขึ้นมาหน่อย แต่ก็ใช้ไม่เป็นอยู่ดี 555
รอพี่ Admin มาช่วย ><"
|
|
|
|
|
Date :
2016-02-03 01:31:57 |
By :
makdonal |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<script language="javascript">
function OpenPopup(intLine)
{
window.open('getData.php?Line='+intLine,'myPopup','width=650,height=200,toolbar=0, menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');
}
function CreateSelectOption(ele)
{
var objSelect = document.getElementById(ele);
var Item = new Option("", "");
objSelect.options[objSelect.length] = Item;
<?php
while($objResult=mysql_fetch_array($objQuery)){
?>
var Item = new Option("<?php echo $objResult["CountryName"];?>", "<?php echo $objResult["CountryCode"];?>");
objSelect.options[objSelect.length] = Item;
<?php
}
?>
}
function CreateNewRow()
{
var intLine = parseInt(document.frmMain.hdnMaxLine.value);
intLine++;
var theTable = document.getElementById("tbExp");
var newRow = theTable.insertRow(theTable.rows.length)
newRow.id = newRow.uniqueID
var newCell
//*** Column No ***//
newCell = newRow.insertCell(0);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center>"+intLine+"</center>";
//*** Column CustomerID ***//
newCell = newRow.insertCell(1);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"txtCustomerID_"+intLine+"\" ID=\"txtCustomerID_"+intLine+"\" VALUE=\"\"></center>";
//*** Column Name ***//
newCell = newRow.insertCell(2);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"txtName_"+intLine+"\" ID=\"txtName_"+intLine+"\" VALUE=\"\"></center>";
//*** Column Email ***//
newCell = newRow.insertCell(3);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"txtEmail_"+intLine+"\" ID=\"txtEmail_"+intLine+"\" VALUE=\"\"></center>";
//*** Column Country Code ***//
newCell = newRow.insertCell(4);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><SELECT NAME=\"txtCountryCode_"+intLine+"\" ID=\"txtCountryCode_"+intLine+"\"></SELECT></center>";
//*** Create Option ***//
CreateSelectOption("txtCountryCode_"+intLine)
//*** Column Budget ***//
newCell = newRow.insertCell(5);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"txtBudget_"+intLine+"\" ID=\"txtBudget_"+intLine+"\" VALUE=\"\"></center>";
//*** Column Used ***//
newCell = newRow.insertCell(6);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"txtUsed_"+intLine+"\" ID=\"txtUsed_"+intLine+"\" VALUE=\"\"></center>";
//*** Column 7 ***//
newCell = newRow.insertCell(7);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
//newCell.setAttribute("OnClick", "OpenPopup('"+intLine+"')");
newCell.innerHTML = "<center><INPUT TYPE=\"BUTTON\" NAME=\"btnPopup_"+intLine+"\" ID=\"btnPopup_"+intLine+"\" VALUE=\"...\" OnClick=\"OpenPopup('"+intLine+"')\"></center>";
//*** Column 7 ***//
newCell = newRow.insertCell(8);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
//newCell.setAttribute("OnClick", "OpenPopup('"+intLine+"')");
newCell.innerHTML = "<center><INPUT TYPE=\"BUTTON\" NAME=\"btnDel_"+intLine+"\" ID=\"btnDel_"+intLine+"\" VALUE=\"-\" OnClick=\"RemoveRowID('"+intLine+"')\"></center>";
document.frmMain.hdnMaxLine.value = intLine;
}
function RemoveRow()
{
intLine = parseInt(document.frmMain.hdnMaxLine.value);
if(parseInt(intLine) > 0)
{
theTable = document.getElementById("tbExp");
theTableBody = theTable.tBodies[0];
theTableBody.deleteRow(intLine);
intLine--;
document.frmMain.hdnMaxLine.value = intLine;
}
}
function RemoveRowID(intLine)
{
// intLine = parseInt(document.frmMain.hdnMaxLine.value);
if(parseInt(intLine) > 0)
{
theTable = document.getElementById("tbExp");
theTableBody = theTable.tBodies[0];
theTableBody.deleteRow(intLine);
intLine--;
document.frmMain.hdnMaxLine.value = intLine;
}
}
</script>
<body OnLoad="CreateNewRow();">
<form name="frmMain" method="post" action="readData.php">
<table width="600" border="1" id="tbExp">
<tr>
<td><div align="center">No </div></td>
<td><div align="center">CustomerID </div></td>
<td><div align="center">Name </div></td>
<td><div align="center">Email </div></td>
<td><div align="center">Country Code </div></td>
<td><div align="center">Budget </div></td>
<td><div align="center">Used </div></td>
<td><div align="center">Popup </div></td>
<td><div align="center">Del </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();">
<input type="submit" name="btnSubmit" value="Submit">
</form>
</body>
</html>
|
ประวัติการแก้ไข 2016-02-03 01:41:07
|
|
|
|
Date :
2016-02-03 01:40:11 |
By :
progamer2000 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับ แต่มันยังมีปัญหาอยู่ตรง
สมมุติ ผมเพิ่มมา 4 row ใส่ข้อมูลทุก row แล้ว ที่นี้ ผมลบ row ที่ 2 ข้อมูลที่ ได้รับออกมา จะมีแค่ row 1 แค่นั้น row 3 , 4 ไม่มีข้อมูลมาครับ
|
|
|
|
|
Date :
2016-02-03 16:01:22 |
By :
makdonal |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|