I have this WORKING code here:
function updatetotal (section, pricetoadd)
{
TotalPrice[section] = pricetoadd;
total = 0;
for(key in TotalPrice)
{
total = total + TotalPrice[key];
}
$("#monthlycost").html("$" + total);
$("#firstpayment").html("$" + total);
}
<input {if $hw_s.disk[$_var].content == $__val.content}checked{/if} type=radio name="order[disk][{$_var}][content]" value="{$__val.content}" price="{$__val.price}" setup="{$__val.setup}" onclick="updatetotal('disk{$_var}', {$__val.price})">
Note that the value is very important. It has to be $__val.content for all of the backend code to function properly.
What I am trying to do is convert above to a dropdown and have the functionality still work properly. The JS function keeps a running total of every selected item and adds them together. With an input type radio it's very simple since the JS function can take a price variable. Unfortunately, with a dropdown (as far as I know), the onChange function has to go be associated with the select, not the option. Unfortunately, since the options are dynamically generated, the select doesn't know anything about the options.
Code so far (not working):
function updatetotaldd(section, elementid)
{
var selectBox = document.getElementById(elementid);
var selectedValue = selectBox.options[selectBox.selectedIndex].value; // does not get what I need since value is a string. I need to somehow access the price of the selected option.
TotalPrice[section] = selectedValue;
for(key in TotalPrice)
{
total = total + TotalPrice[key];
}
$("#monthlycost").html("$" + total);
$("#firstpayment").html("$" + total);
}
<select class="tech" name="order[disk][{$_var}][content]" id="svtech{$_var+1}" data-enablecheckbox="false" onChange="updatetotaldd('disk{$_var}', 'svtech{$_var+1}')">
{foreach key=__var item=__val from=$_val}
<option {if $hw_s.disk.content == $__val.content}selected{/if} value="{$__val.content}" price="{$__val.price}" setup="${$__val.setup}" onSelect="updatetotaldd('disk{$_var}', 'svtech{$_var+1}')">
{$__val.content}
{if $__val.price > 0 && $__val.setup > 0}
<strong> - add ${$__val.price}/Mo + ${$__val.setup} One time fee</strong>
{elseif $__val.price > 0}
<strong> - add ${$__val.price}/Mo</strong>
{elseif $__val.setup > 0}
<strong>- add ${$__val.setup} One time fee</strong>
{/if}
</option>
{/foreach}
</select>
How can I either pass in the price to javascript (whether it be onChange on the select, some other action on the option itself), or somehow have the option have a variable attribute (NOT VALUE)?