2012-07-26 65 views
0

我想创建一个订单,其中字段是产品订单,其中一个按钮,点击时行添加

选择客户:[下拉菜单] 选择产品:[下拉菜单]数量:[]单价:从数据库中查询时,产品选择] TotalPrice:在产品选择和更新时显示量更新]

[添加产品按钮] [提交按钮] [重置]

所以我的问题:

  1. 添加行按钮应该从选择产品添加表单字段。每行都应该有一个唯一的ID,因为它们在数据库中是不同的行。任何帮助是极大的赞赏。

  2. 我如何触发unitprice和totalprice。

回答

0

这似乎是所有的客户端请求,所以我建议你使用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); 
}) 
相关问题