そうですね、3 つのドロップダウン ボックスに値があり、さらに値が追加されます (アイテムの最終価格を示すために追加する約 20 のドロップダウン ボックスを追加することを検討しています。HTML のコードは次のとおりです。
<form id="myform1>
<p>Testing 1</p>
<select id="Test1">
<option value="24">Item one</option>
<option value="29">Item Two<option>
<!--I have the first box going to 20 items-->
</select>
<p>Testing 2</p>
<select id="Test2">
<option value="25">Item one</option>
<option value="100">Item Two<option>
<!--I have the second box going to 10 items-->
</select>
<p>Testing 3</p>
<select id="Test3">
<option value="24">Item one</option>
<option value="100">Item Two<option>
<!--I have the third box going to 10 items-->
</select>
</form>
<button onclick="myFunction()">Update</button>
<p id="demo"></p>
それから私は私のJavascriptを持っています
function myFunction()
{
var a = document.getElementById("list1");
var A = a.options[a.selectedIndex].value;
var b = document.getElementById("list2");
var B = b.options[a.selectedIndex].value;
var c = document.getElementById("list3");
var C = c.options[a.selectedIndex].value;
var IntA = parseInt(A);
var IntB = parseInt(B);
var IntC = parseInt(C);
var x=IntB + IntA;
var y=x + IntC;
var demoP=document.getElementById("demo")
demoP.innerHTML= y;
}
私の問題は、var c を完全に取り出してから var y を取り出して x に計算する場合にのみ機能することです。私は多くの方法を試しましたが、途方に暮れています。乾杯
PS Java スクリプトは、下部の script タグにあります。