this form scriptを使用して合計を自動的に計算しています。今、私はその合計を取得し、PHPとMySQL経由でデータベースに追加する必要があります。JavaScriptとPHPを使用した場合の合計値
totalPrice
divに「名前を付ける」方法がわからないので、その値をデータベースに渡すことができます。
編集:
私はまだデータベースに結果が届きません。フィールドセットには$_POST[totalValue]
、フィールド名にはtotalPrice
を使用しています。
HTML:
<div id="totalPrice"></div></div>
<input type="hidden" name="totalValue" id="totalValue" />
はJavaScript:jQueryのを使用して
$("#vendorform").submit(function(){
var totalValue = document.getElementById('totalValue');
totalValue.value = vendorPrice; //the actual total value
});
function calculateTotal()
{
//Here we get the total price by calling our function
//Each function returns a number so by calling them we add the values they return together
var vendorPrice = getTentPrice() + getElecPrice() + getPropanePrice();
//display the result
var divobj = document.getElementById('totalPrice');
divobj.style.display='block';
divobj.innerHTML = "Total Price Vendor $"+vendorPrice;
}
通常、テーブル内に計算された値を挿入することはお勧めできません。 –
ああ、どうしてですか?私の選択肢は何ですか? – AAAndreAAA
この方法は正規化規則に違反するため、パフォーマンスを向上させるために特定の条件でのみ使用する必要があります。それ以外の場合は、クエリを保存しないでクエリを計算する方がよいでしょう。 –