这是我的查看页面代码: 当我输入订单号时,它会使用ajax代码从表中获取两个表数据。在第一个表中,当我尝试更改数量值时,它将与rate相乘并显示在我完成的总列中。 我的问题是,当我更改第一个表的数量时,应将其乘以第二个表的wgt / q并在第二个表列的权重中显示出来。 我不处理第二张表,请帮我解决这个问题
这是我用来从表中获取数据的ajax代码 我的Ajax代码:
<script type="text/javascript">
$(document).ready(function(){
$('#orderno').on('input change',function(){
var orderno = $("#orderno").val();
var supplier = $("#supplier").val();
$.ajax({
type: "POST",
url: "<?php echo base_url();?>Inventory/Sales_fetch",
data: {
orderno:orderno
},
datatype: 'json',
success: function (data) {
var res = jQuery.parseJSON(data);
if(supplier == res.pname){
fetch();
item_type();
$('#pono').val(res.pono);
$('#podate').val(res.podate);
$('#pname').val(res.accName);
$('#bname').val(res.accName);
$('#text').val(res.addrs);
}
else{
alert("Invalid Order No for this Party");
}
}
});
});
});
</script>
<script type="text/javascript">
function fetch() {
var orderno = $("#orderno").val();
$.ajax({
type: "POST",
url: "<?php echo base_url();?>Inventory/Billfetch",
data: {
orderno:orderno
},
datatype: 'json',
success: function (data) {
$('#Product_Name_div').html(data);
}
});
}
</script>
<script type="text/javascript">
function item_type(){
var orderno = $("#orderno").val();
$.ajax({
type: "POST",
url: "<?php echo base_url();?>Inventory/itemfetch",
data: {
orderno:orderno
},
datatype: 'json',
success: function (data) {
$('#itemtype').html(data);
}
});
}
</script>
我的模型代码:
function fetch_item1($orderno){
$this->db->where("orderno",$orderno);
$this->db->select('*');
$this->db->join('item_master', 'item_master.id = order_item.itname', 'left');
$this->db->from('order_item');
$query_result = $this->db->get()->result();
$output = '<center><table class="table table-bordered table-striped table-xxs" id="tb2">
<tbody>';
if($query_result !='false'){
$i=0;
foreach ($query_result as $key => $value) {
$output .='<tr>
<td><a href="javascript:void(0);"><span class="glyphicon glyphicon-remove" id="remove"></span></a></td>
<td><input style="width:50px" name="sno[]" type="text" class="form-control input-xs" value="'.$value->sno.'" ></td>
<td><input style="width:50px" name="rate[]" type="text" class="form-control input-xs rate" value="'.$value->rate.'" ></td>
<td><input style="width:250px" name="itemname[]" type="text" class="form-control input-xs" value="'.$value->itemname.'" ></td>
<td><input style="width:80px" name="qty[]" type="text" class="form-control input-xs qty" value="'.$value->qty.'" id="qty_'.$i.'" onchange="calculate('.$i.')"></td>
<td><input style="width:80px" name="unit[]" type="text" class="form-control input-xs" >
<td><input style="width:90px" name="total[]" type="text" class="form-control input-xs total" value="'.$value->tot.'"> </td>
<td><input style="width:150px" name="desc[]" type="text" class="form-control input-xs" > </td>
<td><a href="javascript:void(0);" style="font-size:18px;" class="addMore" title="Add More Person"><span class="glyphicon glyphicon-plus"></td>
</tr>';
$i++;
}
$output .="</tbody>
</table></center>";
echo $output;
}
}
function itemfetch($orderno){
$this->db->where("orderno",$orderno);
$this->db->select('*');
$this->db->join('item_master', 'item_master.id = order_item.itname', 'left');
$this->db->join('item_type', 'item_type.name = item_master.itemname', 'left');
$this->db->from('order_item');
$query_result = $this->db->get()->result();
$output = '<center><table class="table table-bordered table-striped table-xxs" id="tb2">
<tbody>';
if($query_result !='false'){
$i=0;
foreach ($query_result as $key => $value) {
$output .='<tr>
<td><input style="width:120px" name="name[]" type="text" class="form-control input-xs" value="'.$value->itname.'" ></td>
<td><input style="width:60px" name="wgtq[]" type="text" class="form-control input-xs wgtq" value="'.$value->wgt.'" ></td>
<td><input style="width:90px" name="wgt[]" type="text" class="form-control input-xs wgt" > </td>
</tr>';
$i++;
}
$output .="</tbody>
</table></center>";
echo $output;
}
}
我的第一张表格计算代码:
<script type="text/javascript">
function calculate(id){
var tot = 0;
var total = 0;
var qty = document.getElementsByClassName("qty");
var rate = document.getElementsByClassName("rate");
for(var i = 0; i < qty.length; i++)
{
tot = parseFloat(qty[i].value) * parseFloat(rate[i].value);
total += parseInt(tot);
$(".total").eq(i).val(tot);
}
$("#Total").val(total)
}
</script>