[英]How do I add another row in the table on select an option from a drop down?
这是我的代码:
<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?
另外,我要添加所有“总计”文本框的总数。
编辑:
我下面有一些代码,添加了新行。 但是,当我从最新行的下拉列表中选择一个值时,应该添加新行。 现在,它仅添加了FIRST下拉菜单。
使用此代码。
$(function() {$(".ddplaceholder").change(function() {
$('<tr><td>new td1</td><td>new td2</td></tr>').insertAfter($(this).closest('tr')); }); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.