如何在php中汇总多个文本框数据循环

时间:2017-03-16 10:00:40

标签: javascript php jquery

我希望我的问题是正确的。下面是我想要拍摄的照片:

http://i58.photobucket.com/albums/g248/shevcenkoandry/form%20po_zpsqadzjeaf.jpg

我已成功从表中检索数据,并且我想从文本框中计算值。我怎样才能做到这一点?

我目前的源代码:

<!doctype html>
<html>
    <head>
        <title>Lookup Modal Bootstrap 3</title>
        <link rel="stylesheet" href="../css/bootstrap.css"/>
        <link rel="stylesheet" href="../datatables/dataTables.bootstrap.css"/>

  <script src="../js/jquery-ui 1.12.1.js"></script>
  <script src="../js/bootstrap.js" ></script>
    </head>
    <body>

  <div class="container"><br/><br/><br/>

    <div class="panel panel-success">
    <div class="panel-heading" >
         <h3 class="panel-title"><strong> Purchase Order</strong> <a href="po.php" class="btn btn-success btn-sm"><strong> Back </strong></a></h3> 
  </div>
  <div class="panel-body">

         <form action="poSimpan.php" name="aku" id="aku">
          <table align="left" class="table table-bordered table-hover ">

            <tr valign="baseline">
              <td nowrap align="right"><strong>No. PO:</strong></td>
              <td><input type="text" id="poNo" name="poNo" size="32"></td>
              <td><strong>No. PR:</strong></td>
              <td><input type="text"  name="prNo" id="prNo" placeholder="Request Number" readonly />  <button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal">. . .</button>
            </tr>
            <tr valign="baseline">
              <td nowrap align="right"><strong>Supplier:</strong></td>
              <td><select name="supplier" id="supplier" onChange="changeValue(this.value)" >
              <option value=0>-Choose-</option>
<?php 
    $con = mysqli_connect('localhost', 'root', '', 'a.karat');
    $result = mysqli_query($con,'select * from supplier ');
    $result = mysql_query("select * from supplier");    
    $jsArray = "var kode = new Array();\n";        
    while ($row = mysqli_fetch_array($result)) {    
        echo '<option value="' . $row['supplierName'] . '">' .   $row['supplierName'] . '</option>';    

}      
?> 
                </select></td>

              <td><strong>Branch :</strong></td>
              <td><input type="text" id="Branch" name="Branch"  size="20"></td>
            </tr>
            <tr valign="baseline">
               <td nowrap align="right"><strong> P.O Date</strong></td>
               <td><input type="text" name="date_po" id="date_po"  size="20"></td>

              <td><strong>Delivery Date:</strong></td>
              <td><input type="text" id="date_delivery" name="date_delivery"  size="32"></td>
            </tr>
            <tr valign="baseline">
              <td nowrap align="right"><strong></strong></td>
              <td></td>

              <td><strong>Note:</strong></td>
              <td><input type="text" id="note" name="note"  size="32"></td>
            </tr>
           </table>      

         <div class="row">
             <div class="col-md-5">

             </div>
         </div>

           <h4><strong>Product Detail </strong></h4>
<table class="table table-bordered table-hover table-striped" >
   <thead>
  <tr>
    <th scope="row">&nbsp;</th>
    <th scope="row"><strong>Product Code</strong></th>
    <th scope="row"><strong>Product Name</strong></th>
    <th scope="row"><strong>QTY</strong></th>
    <th scope="row"><strong>Price</strong></th>
    <th scope="row"><strong>Discount</strong></th>
    <th scope="row"><strong>Total</strong></th>


  </tr>
  </thead>
  <tbody id="product_table">

  </tbody>
</table>
<table width="400" border="0" align="right">
  <tr>
    <th scope="row">Tax 10%</th>
     <td>:</td>
    <td><input name="tax" id="taxt" type="text"></td>
  </tr>
  <tr>
    <th scope="row">Grand Total</th>
     <td>:</td>
    <td><input name="grandtotal" id="grandtotal" type="text"></td>
  </tr>
</table>

           <input type="submit" value="Save" name="product_submit" id="product_submit" class="btn btn-primary" />
        </form>

        <!-- Modal -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog"  aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog" style="width:800px">
                <div class="modal-content">
                    <div class="modal-header">
                         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">Lookup     </h4>
                    </div>
                    <div class="modal-body">
                        <table id="lookup" class="table table-bordered table-hover table-striped">
                            <thead>
                                <tr>
                                    <th>No. PR</th>
                                    <th>branch</th>
                                </tr>
                             </thead>
                             <tbody>
<?php
    $con = mysqli_connect('localhost', 'root', '', 'a.karat');
    $sql = mysqli_query($con,'select * from pr ');
    while ($r = mysqli_fetch_array($sql)) {
?>
                                    <tr class="pick" no="<?php echo $r['prNo']; ?>", branch="<?php echo $r['branch'] ?>">
                                        <td><?php echo $r['prNo']; ?></td>
                                        <td><?php echo $r['branch']; ?></td>
                                    </tr>
<?php
    }
?>

                            </tbody>
                        </table>  
                    </div>
                 </div>
            </div>
        </div>
       <script src="../js/jquery-1.11.2.min.js"></script>
        <script src="../js/bootstrap.js"></script>
        <script src="../datatables/jquery.dataTables.js"></script>
        <script src="../datatables/dataTables.bootstrap.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/>


        <script type="text/javascript">

            $(document).on('click', '.pick', function (e) {
                document.getElementById("prNo").value = $(this).attr('no');
                document.getElementById("branch").value = $(this).attr('branch');

                var no=$(this).attr('no');

                $.ajax({
                    type:"post",
                    data:"&product_id=1&prno="+no,
                    url:"POtabel.php",
                   success:function(result)
                    {
                        $("#product_table").html(result);
                    }
                });
                $('#myModal').modal('hide');
            });

            $(function () {
                 $("#lookup").dataTable();
             });
</script>

    </body>
 </html>

这是目标文件

POtable.php

<?php
$con = mysqli_connect('localhost', 'root', '', 'a.karat');
if(isset($_POST['product_id']))
{
    $prno=$_POST['prno'];

    $i=1;
    $sql = mysqli_query($con,"select * from detail_pr where prNo='$prno'");
    while ($r = mysqli_fetch_array($sql)) {
        echo '<tr>
    <td><input type="checkbox" name="check[]" id="check'.$i.'" value="'.$i.'"></td>
    <td><label for="productCode"></label>
      <input type="text" name="productCode'.$i.'" id="productCode'.$i.'" readonly value="'.$r["productCode"].'" size="12"></td>
    <td><label for="productName"></label>
      <input type="text" name="productName'.$i.'" id="productName'.$i.'" readonly value="'.$r["productName"].'"size="35"></td>
    <td><label for="qty"></label>
      <input type="text" name="qty'.$i.'" id="qty'.$i.'" readonly value="'.$r["qty"].'" size="8"></td>
    <td><input type="text" name="price'.$i.'" id="price'.$i.'" size="10"></td>
    <td><input type="text" name="disc'.$i.'" id="disc'.$i.'" size="10"></td>
    <td><input type="text" name="total'.$i.'" id="total'.$i.'" size="10"></td>
  </tr>';
  $i++;
    }
}

?>
<script type="text/javascript">
function calculate(id){
var quantity = document.getElementById('qty'+id).value;
var price = document.getElementById('price'+id).value;
var sum = parseInt(quantity,10)*parseInt(price,10); 
document.getElementById('total'+id).value = sum;
}
</script>

感谢先进的任何帮助。

0 个答案:

没有答案