【发布时间】:2016-06-05 05:40:54
【问题描述】:
这是我的代码:
<table class="inventory" style="float:left;">
<tbody>
<tr>
<th>Date bought</th>
<th>Item</th>
<th>Quantity</th>
<th>Total</th>
</tr>
<tr>
<td>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="style.css">
<script>
$(document).ready(function() {
$( "#datepicker" ).datepicker();
});
</script>
<input type="text" id="datepicker"/>
</td>
<td>
<select name="item_name_update" value="item_name_update" class="form-control ddplaceholder" style="width:220px; padding-left:40px;font-size:18px;font-family:Roboto;">
<option value="" disabled selected>Select Item</option>
<?php
$sth = $conn->prepare('Select item_name From item');
$sth->execute();
$data = $sth->fetchAll();
foreach ($data as $row ){
if($row['item_name']!="")
echo ' <option id=\"ItemName\" name=\"ItemName\" value="' .$row['item_name']. '">'.$row['item_name'].'</option>';
}?>
</select>
</td>
<td>
<input type="text" placeholder="Quantity" name="Quantity" id="Quantity"/>
</td>
<td>
<input type="text" placeholder="Total" value=""/>
</td>
</tr>
<?php $totalCost="";
if(!empty($_POST['item_name_update']) && !empty($_POST['datepicker']) && !empty($_POST['Quantity'])){
$sth = $conn->prepare('Select price_per_unit From bill where item=:item and date=:date');
$sth->execute(array(':item'=>$_POST['item_name_update'], ':date'=>$_POST['datepicker']));
$data = $sth->fetchAll();
foreach ($data as $row ){
$totalCost=($row['price_per_unit']*$_POST['Quantity']);
}}
?>
</tbody>
</table>
每次从下拉列表中选择一个项目时,我想在表格中添加一行。我怎么做?有一个简单的解决方案吗?是否添加循环并在选择下拉菜单中添加 document.change?
另外,我想添加所有文本框的总数。
编辑:
我在下面得到了一些添加新行的代码。但是当我从最新行的下拉列表中选择一个值时,应该添加新行。现在它正在添加仅选择第一个下拉列表。
【问题讨论】: