請求書フォームに、25行のテーブルがあります
<table border="1" align="center">
<thead>
<tr>
<th>#</th>
<th>Item Name</th>
<th>Item Code</th>
<th>Quantity</th>
<th>Price</th>
<th>Amount</th>-->
<th>Net Amount</th>
</tr>
</thead>
<tbody>
<?php for($i=1 ; $i<=25 ; $i++) { ?>
<tr>
<th> <?php echo "$i"; ?> </th>
<td><input id="itemName" onBlur="loadAllField()" class="orderInput" type="text" align="center" ></td>
<td><input id="itemCode" onBlur="loadAllField()" class="orderInput" type="text" align="center" ></td>
<td><input id="quantity" class="orderInput" onKeyPress="calqtyprice()" type="text" align="center" ></td>
<td><input id="price" class="orderInput" type="text" align="center" readonly></td>
<td><input id="netAmount" class="orderInput" type="text" align="center" readonly ></td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<td id="tdTotal" colspan="2" style="font-size:16px"> <b>Totals</b></td>
<td id="totalspace" colspan="3"> </td>
<td><input id="netTotalAll" class="orderInput" type="text" readonly> </td>
</tr>
</tfoot>
</table>
<p id="msg" align="center"> </p>
Javaスクリプト関数は
function loadAllField ()
{
var itemName = document.getElementById("itemName");
var itemCode = document.getElementById("itemCode");
var quantity = document.getElementById("quantity");
var price = document.getElementById("price");
var netAmount = document.getElementById("netAmount");
var msg = document.getElementById("msg");
msg.innerHTML = "";
// check is fill
if ( ( (itemName == null ) || (itemName.value == "") ) && ((itemCode == null ) || (itemCode.value == "")) )
{
msg.innerHTML = "";
itemName.value = null;
itemCode.value = null;
quantity.value = null;
price.value = null;
netAmount.value = null;
}
// load id if item name give and load name if item code given
if ((itemName.value == "detol") || (itemCode.value=="1") )
{
var itemName = document.getElementById("itemName");
var itemCode = document.getElementById("itemCode");
var quantity = document.getElementById("quantity");
var price = document.getElementById("price");
var netAmount = document.getElementById("netAmount");
var msg = document.getElementById("msg");
msg.innerHTML = "";
itemName.value = "detol";
itemCode.value = "1";
quantity.value = "";
price.value = "40";
netAmount.value = "";
}
else if ( (itemName.value == "robin") || (itemCode.value == "2") )
{
msg.innerHTML = "";
itemName.value = "robin";
itemCode.value = "2";
quantity.value = "";
price.value = "90";
netAmount.value = "";
}
else
{
msg.innerHTML = "Product not find";
//msg.innerHTML.blink();
itemName.value = "";
itemCode.value = "";
quantity.value = "";
price.value = "";
netAmount.value = "";
}
} // end of load id function
function calqtyprice()
{
for ( i=1; i==25; i++)
{
var price = document.getElementById("price");
var quantity = document.getElementById("quantity");
var netAmount = document.getElementById("netAmount");
var netTotalAll = document.getElementById("netTotalAll");
var netamt = price.value * quantity.value ;
netAmount.value = netamt;
netTotalAll = netAmount.value + netAmount.value;
}
}
問題は、すべての行を調べて入力から値を取得し、最後の行に正味合計を計算して表示する方法です。
または、これまたはチュートリアルのメカニズムはありますか。