ok, I'm not sure I know how to ask this question, but I've created a table that allows the user to add rows. The problem is, upon submit only the last row creates variables. How can I make sure every cell in every row sets a different variable?
This is going to be a purchase order system.
Here is my code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert Table Row using DOM</title>
<script language="javascript">
function addRow()
{
var tbody = document.getElementById("po_table").getElementsByTagName("tbody")[0];
var row = document.createElement("TR");
var cell1 = document.createElement("TD");
var cell2 = document.createElement("TD");
var cell3 = document.createElement("TD");
var inp1 = document.createElement("INPUT");
inp1.setAttribute("type","text");
inp1.setAttribute("name","quantity");
cell1.appendChild(inp1);
var inp2 = document.createElement("INPUT");
inp2.setAttribute("type","text");
inp2.setAttribute("name","description");
cell2.appendChild(inp2);
var inp3 = document.createElement("INPUT");
inp3.setAttribute("type","text");
inp3.setAttribute("name","unit_cost");
cell3.appendChild(inp3);
row.appendChild(cell1);
row.appendChild(cell2);
row.appendChild(cell3);
tbody.appendChild(row);
//alert(row.innerHTML);
}
</script>
</head>
<body>
<form method="post" action="review_po.php">
<table id="po_table" border="1">
<tbody>
<tr>
<th bgcolor="#c1c1c1">Quantity</th>
<th bgcolor="#c1c1c1">Description</th>
<th bgcolor="#c1c1c1">Unit Cost</th>
</tr>
<tr>
<td><input type=text name="quantity"></td>
<td><input type=text name="description"></td>
<td><input type=text name="unit_cost"></td>
</tr>
</tbody>
<tfoot>
<tr>
<th bgcolor="#e0e0e0">1</th>
<th bgcolor="#e0e0e0">Shipping</th>
<td><input type=text name="shipping"></td>
</tr>
<tr>
<th bgcolor="#e0e0e0">1</th>
<th bgcolor="#e0e0e0">Tax</th>
<td><input type=text name="tax"></td>
</tr>
</tfoot>
</table>
<input type="button" value="Insert Row" onClick="addRow();">
<input type="submit" value="Review" name="review_po">
</form>
</body>
</html>
right now it goes to this page:
<?php
//convert to variables
$quantity = $_POST['quantity'];
$description = $_POST['description'];
$unit_cost = $_POST['unit_cost'];
$extended_cost = $_POST['extended_cost'];
$shipping = $_POST['shipping'];
$tax = $_POST['tax'];
?>
<?php echo $quantity; ?><br>
<?php echo $description; ?><br>
<?php echo $unit_cost; ?><br>
<?php echo $extended_cost; ?><br>
<?php echo $shipping; ?><br>
<?php echo $tax; ?><br>
here is the page:
http://po.shopphgmag.com/create_po.html
Thanks for looking