Advertisement
lalatino

invoice_form.php

Jun 23rd, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 3.57 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>invoice_form.php</title>
  5. <script type="text/javascript">
  6.  
  7. function loadAllFields(i,elemType)
  8. {
  9.     var msg = document.getElementById("msg");
  10.     var itemName = document.getElementById("itemName"+i);
  11.     var itemCode = document.getElementById("itemCode"+i);
  12.     var quantity = document.getElementById("quantity"+i);
  13.     var price = document.getElementById("price"+i);
  14.     var netAmount = document.getElementById("netAmount"+i);
  15.     var items = [{n:'deto1', c:1, p:40},
  16.         {n:'robin', c:2, p:90}];
  17.     var found = false; // find item
  18.     for (var j=0; j<items.length; j++) {
  19.         if (elemType=='name' && itemName.value == items[j].n) {
  20.             found = j;
  21.         }
  22.         if (elemType=='code' && itemCode.value == items[j].c) {
  23.             found = j;
  24.         }
  25.     }
  26.     //console.log(i, elemType, found, itemCode.value, items[0].c);
  27.     if (found===false) {
  28.         msg.innerHTML = "Product not found";
  29.         /*if (elemType=='name')*/ itemCode.value = '';
  30.         /*else if (elemType=='code')*/ itemName.value = '';
  31.         quantity.value = "";
  32.         price.value = "";
  33.         netAmount.value = "";
  34.         calcNetTotal();
  35.     }
  36.     else {
  37.         msg.innerHTML = "Found";
  38.         itemName.value = items[found].n;
  39.         itemCode.value = items[found].c;
  40.         price.value = items[found].p;
  41.         if (quantity.value == '') { quantity.value = "1"; }
  42.         calqtyprice(i);
  43.     }
  44. } // end of load id function
  45.  
  46. function calqtyprice(i) {
  47.     var price = document.getElementById("price"+i);
  48.     var quantity = document.getElementById("quantity"+i);
  49.     var n = parseInt(quantity.value,10);
  50.     if (n<1 || isNaN(n)) { n=1; }
  51.     quantity.value = n;
  52.     //console.log(n);
  53.     var netAmount = document.getElementById("netAmount"+i);
  54.     var netamt = price.value * quantity.value;
  55.     netAmount.value = netamt;
  56.     calcNetTotal();
  57. }
  58. function calcNetTotal(){
  59.     var netTotalAll = document.getElementById("netTotalAll");
  60.     var sum = 0;
  61.     for (var j=1; j<=25; j++) {
  62.         var netAmount = document.getElementById("netAmount"+j).value;
  63.         if (netAmount!='') {
  64.             sum += parseFloat(netAmount);
  65.         }
  66.     }
  67.     netTotalAll.value = sum.toFixed(2);
  68. }
  69. </script>
  70. <style type="text/css">
  71.     table { margin:0px auto; border:1px solid #888; }
  72.     table td, table th { border:0; padding:0; }
  73.     table tbody tr td:first-child, #netTotalAll {
  74.         font-weight:bold; min-width:4em; text-align:center;
  75.     }
  76.     table tbody tr td input{
  77.         padding:8px 3px;
  78.     }
  79.     table td input { width:98%; border:1px solid #ccc; }
  80.     table tr:hover * { background-color:#efe;  }
  81.     #tdTotal { padding-left:1em; }
  82.     input[id^=netAmount] { text-align:center; }
  83. </style>
  84. </head>
  85. <body>
  86.  
  87. <p id="msg" align="center"> </p>
  88.  
  89.  
  90. <table>
  91. <thead>
  92. <tr>
  93. <th>#</th>
  94. <th>Item Name</th>
  95. <th>Item Code</th>
  96. <th>Quantity</th>
  97. <th>Price</th>
  98. <th>Net Amount</th>
  99. </tr>
  100. </thead>
  101.  
  102. <tbody>
  103. <?php for($i=1 ; $i<=25 ; $i++) {
  104. echo '<tr>
  105. <td>'.$i.'</td>
  106. <td><input id="itemName'.$i.'" onBlur="loadAllFields('.$i.',\'name\')" class="orderInput" type="text" /></td>
  107. <td><input id="itemCode'.$i.'" onBlur="loadAllFields('.$i.',\'code\')" class="orderInput" type="text" /></td>
  108. <td><input id="quantity'.$i.'" class="orderInput" onKeyUp="calqtyprice('.$i.')" type="text" /></td>
  109. <td><input id="price'.$i.'" class="orderInput" type="text" readonly /></td>
  110. <td><input id="netAmount'.$i.'" class="orderInput" type="text" readonly /></td>
  111. </tr>';
  112. }
  113. ?>
  114. </tbody>
  115.  
  116. <tfoot>
  117. <tr>
  118. <td id="tdTotal" colspan="2" style="font-size:16px"> <b>Totals</b></td>
  119. <td id="totalspace" colspan="3"> </td>
  120. <td><input id="netTotalAll" class="orderInput" type="text" readonly> </td>
  121. </tr>
  122.  
  123. </tfoot>
  124. </table>
  125. <!-- http://stackoverflow.com/questions/17260771/mulitple-rows-of-table-having-input-tag -->
  126. </body>
  127. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement