2016-08-13 8 views
-5

アイテムの数量を入力するフィールドが1つあるフォームを作成しています。JavaScriptのリアルタイム計算:アイテムのテキストフィールドと固定価格レートに基づいて

固定価格と数量に基づいて商品の費用を計算したいと思います。

JavaScriptを使用してどのように実現できるのでしょうか。後でより多くの製品を追加するために -

​​

は、私は、配列内の各アイテムの価格をホストします。

私が頼んでいることを理解するために、下の図を参照してください。私は本当に私の悪い英語のために申し訳ありません。

+0

https://developer.mozilla.org/en-US/docs/Web/Events/input – Teemu

+1

@Teemu - 私が思うhttps://developer.mozilla.org/en-US/docs/Web/JavaScript最初に –

+0

@Teemu thanks :) – dragonball

答えて

0
element.onkeypress = function() { // element should be your input field 
    var value = this.value; // get the value of the field 
    value *= cost; // multiply value by cost and save result; change cost to suit your needs 
    // set outputelement to the element where you show the result 
    outputelement.innerHTML = value; // set the text of the output field to the result; 
} 
関連する問題