单击按钮时添加行的“产品订单”窗体


Product Order form where row is added when clicked on a button

我想创建一个字段为的订单

选择客户:[下拉菜单]选择产品:【下拉菜单】数量:【】单价:【选择产品时从数据库查询】总价:【选择商品时显示,更新数量时更新】

【添加产品按钮】【提交按钮】【重置】

所以我的问题是:

  1. "添加行"按钮应添加"来自选择产品"的表单字段。这一行中的每一行都应该有一个唯一的id,因为它们是数据库中的不同行。非常感谢您的帮助。

  2. 如何触发单价和总价。

这似乎都是客户端请求,所以我建议您使用jQuery来解决您的问题。我将在示例中使用的所有函数都可以在该网站上找到,stackoverflow上有很多示例可以解决您的所有疑问。现在回答问题:

1。我并没有真正得到你想要的,但你应该简单地使用点击事件在addRow按钮上生成一个事件:

$('AddRow').click(function(e){
e.preventDefault(); //this avoid the default button action (submit/send)
var last_id = $('row').last().attr('id'); //retrieve the id of the last added row you probably will have to strip/transform it since id shouldn't be only number
$('row').last().append('insert here html with form fields of the new row with the (last_id+1)');
});

2。要检索UnitPrice,您应该使用ajax调用,使用$('product').change(function(){});来触发事件并通过ajax检索结果。一旦填充了该字段,就可以使用一个简单的jquery/javascript函数来根据数量字段日常计算总价:

$('Quantity').change(function(){
     //add here control to check if fields are empty/wrongly set
    var UnitPrice = parseFloat($('UnitPrice').val());
    var Quantity = parseInt($('Quantity').val());
    $('TotalPrice').val(UnitPrice*Quantity);
})