Hi
I use js to create a dynamic table. User can input each row of data.
There is one input field: productid.
There are 2 display field in the table: productid and quantity
When user input productid, press add button, it calls add() js.
The js creates the cell and display the innertext value.
The quantity needs to retrieve from inventory table by using the productid as where condition.
<? $query = "SELECT qty FROM inventory WHERE productid=" ?> document.getElementById("productid").value;
has error:
Parse error: syntax error, unexpected '<'
How should I do it?
<script language="javascript">
function add(){
var table = document.getElementById("table1");
var row = table.insertRow();
//product id
var pn = row.insertCell();
pn.innerText = document.getElementById("productid").value;
//quantity
var d = row.insertCell();
<? $query = "SELECT qty FROM inventory WHERE productid=" ?> document.getElementById("productid").value;
<? $query_result = mysql_query($query);
while( $item = mysql_fetch_array($query_result)){
list($qty) = $item;
$dp=$qty;
}
?>
d.innerText = <?echo $dp; ?>;
var r = row.insertCell();
</script>
Product ID<input type="text" id="productid" name="last_productid" />
<input type="button" value="Add" onclick="return add();" />
<table id="table1" border="1">
<tr><td>ProductID</td><td>Quantity</td></tr>
</table>