我試圖在即時通訊工作的網頁內部創建一個JavaScript塊。自從高中我還沒有做javascript和它似乎沒有要回來給我:(Javascript將值添加到單選按鈕以輸入價格
在這個代碼塊我想有4套廣播按鈕,每一個選擇採摘時間, 價格會inputed對每個無線電設備組的一個變量。即
var firstPrice = $25
var secondPrice = $56
var thirdPrice = $80
var fourthPrice = $90
則每個無線電設備組具有一個選擇之後會有附着在提交按鈕的功能,增加了構成每個價格以顯示隱藏字段內的最後量
var totalPrice = (firstPrice + secondPrice + thirdPrice + fourthPrice)
我的問題是,我如何將一個數值附加到一個組中的單選按鈕,同名,但id在每個組中都不相同。然後,我創建一個函數,將所有價格組合起來,然後將提交按鈕設置爲onClick = totalPrice(); 下面是一組單選按鈕的例子:
<label>
<input type="radio" name="model" value="radio" id="item_0" />
item 1</label>
<br />
<label>
<input type="radio" name="model" value="radio" id="item_1" />
item2</label>
<br />
<label>
<input type="radio" name="model" value="radio" id="item_2" />
item3</label>
<br />
<label>
<input type="radio" name="model" value="radio" id="item_3" />
Item4</label>
<br />
<label>
<input type="radio" name="model" value="radio" id="item_4" />
item5</label>
</form>
然後我的腳本看起來像:
function finalPrice90{
var selectionFirst = document.modelGroup.value;
var selectionSecond = document.secondGroup.value;
var selectionThird = document.thirdGroup.value;
var selectionFourth = document.fourthGroup.Value;
var totalPrice = (selectionFirst + selectionSecond + selectionThird + selectionFourth);
}
如果您使用的提交按鈕更新價格,那麼用戶將只能看到更新後的價格爲一秒鐘左右,直到頁面從提交刷新。您希望在按下提交之前更新價格(並確保您重新計算服務器的價格)。 – RobG