 |
|
รบกวนขอคำแนะนำหน่อยครับ ว่าถ้าต้องการนำค่าที่เรากรอก โดยเรากรอกข้อมูลลงใน ช่อง input ที่เกิดจากการสร้างด้วย createElement
น่ะครับ ตาม code ด้านล่างเลยครับ ถ้าผมต้องการนำค่าที่กรอก ไปเชฟลงฐานข้อมูล ผมต้องเขียน code อย่างไงครับ
<script>
function addRowToTable()
{
var tbl = document.getElementById('datatable');
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow + 1
var iteration = lastRow;
var row = tbl.insertRow(lastRow);
// Number Cell
var cellLeft = row.insertCell(0);
var textNode = document.createTextNode(iteration);
//cellLeft.setAttribute('bgColor', '#CCCCCC');
cellLeft.setAttribute('align', 'center');
cellLeft.appendChild(textNode);
// P/N Cell
var cellRight1 = row.insertCell(1);
var el = document.createElement('input');
//cellRight1.setAttribute('align', 'center');
//cellRight1.setAttribute('bgColor', '#CCCCCC');
el.setAttribute('type', 'text');
el.setAttribute('name', 'txtPartNumber' + iteration);
el.setAttribute('id', 'txtPartNumber' + iteration);
el.setAttribute('size', '30');
cellRight1.appendChild(el);
// Description Cell
var cellRight2 = row.insertCell(2);
var e2 = document.createElement('input');
//cellRight2.setAttribute('align', 'center');
//cellRight2.setAttribute('bgColor', '#CCCCCC');
e2.setAttribute('type', 'text');
e2.setAttribute('name', 'txtDescription' + iteration);
e2.setAttribute('id', 'txtDescription' + iteration);
e2.setAttribute('size', '30');
cellRight2.appendChild(e2);
// Quantity Cell
var cellRight3 = row.insertCell(3);
var e3 = document.createElement('input');
//cellRight3.setAttribute('align', 'center');
//cellRight3.setAttribute('bgColor', '#CCCCCC');
e3.setAttribute('name', 'qty' + iteration);
e3.setAttribute('id', 'qty' + iteration);
e3.setAttribute('cols', '42');
//e3.setAttribute('wrap','VIRTUAL');
cellRight3.appendChild(e3);
// UnitPrice Cell
var cellRight4 = row.insertCell(4);
var e4 = document.createElement('input');
var text = document.createTextNode("");
//cellRight4.setAttribute('align', 'center');
//cellRight4.setAttribute('bgColor', '#CCCCCC');
e4.setAttribute('type', 'text');
e4.setAttribute('name', 'UnitPrice' + iteration);
e4.setAttribute('id', 'UnitPrice' + iteration);
e4.setAttribute('size', '3');
cellRight4.appendChild(text);
cellRight4.appendChild(e4);
// Amount Cell
var cellRight5 = row.insertCell(5);
var e5 = document.createElement('input');
e5.setAttribute('type', 'text');
e5.setAttribute('name', 'amount' + iteration);
e5.setAttribute('id', 'amount' + iteration);
e5.setAttribute('size', '7');
//cellRight5.setAttribute('align', 'center');
//cellRight5.setAttribute('bgColor', '#CCCCCC');
//cellRight5.appendChild(document.createTextNode(""));
cellRight5.appendChild(e5);
}
function sumx()
{
var table = document.getElementById('datatable');
var total =0;
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
document.formx.elements('amount'+i).value = document.formx.elements('qty'+i).value * document.formx.elements('UnitPrice'+i).value;
total = total + parseInt(document.formx.elements('amount'+i).value);
}
document.formx.elements('txtTotal').value = total;
}
function removeRowFromTable()
{
var tbl = document.getElementById('datatable');
var lastRow = tbl.rows.length;
if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}
</script>
Tag : PHP, MySQL, Ms SQL Server 2005, Ms SQL Server 2008, CakePHP
|
|
 |
 |
 |
 |
Date :
2010-09-03 09:37:14 |
By :
num |
View :
948 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |