var calculations = new Hash({})
function calcPrice() {
var f = document.forms['calculator']
var price = 0
calculations.each(function(pair) {
if(f[pair.key] == null){
alert(pair.key)
}
if(pair.value['fieldtype'] == 'counter' && f[pair.key].value.match(/^\d+$/)){
price += f[pair.key].value * pair.value['price']
}
if(pair.value['fieldtype'] == 'radio'){
val = getRadioValue(f[pair.key])
} else {
val = f[pair.key].value
}
if(pair.value['fieldtype'] == 'radio' || pair.value['fieldtype'] == 'select'){
if(val != 0){
price += pair.value['prices'][val]
}
}
})
$('pricevalue').innerHTML = price + ' .'
}
function getRadioValue(radio) {
for(i = 0; i < radio.length; i++){
if(radio[i].checked)
return radio[i].value
}
return 0;
}
calculations['units'] = $H({ fieldtype:'counter', price:5.50 })
<input type="text" value="2" name="counter">
calculations("color") = $H({ fieldtype:'select', prices:$H({white:20.95,red:49.55}) })
<select name="color">
<option value="white"></option>
<option value="red"></option>
</select>
calculations("color") = $H({ fieldtype:'radio', prices:$H({white:20.95,red:49.55}) })
<input type="radio" name="color" value="white" />
<input type="radio" name="color" value="red" />
Source: https://habr.com/ru/post/13285/