Hi all,
I have a form with several SELECT boxes and based on the user's selection a value appears. This is fully working.
Now I want a script that calculates the SUM of these values either automatically or when pressing a button.
The full code I have so far is this:
The JavaScript:
<script type="text/javascript">
window.onload=function(a,b)
{
value=document.getElementById('value1'),
combobox=document.getElementById('first');
combobox.onchange=function(a)
{
document.getElementById('value1').innerHTML = "€ " +this.value;
}
value2=document.getElementById('value2'),
combobox2=document.getElementById('second');
combobox2.onchange=function(b)
{
document.getElementById('value2').innerHTML = "€ " +this.value;
}
}
function changeText(){
var sum;
sum= (value * 1) + (value2 * 1);
document.getElementById('sum').innerHTML = "€ " +this.value;
}
</script>
The HTML:
<ol>
<li><label><span>First</span></label>
<select name="block1" id="first">
<option value="0">Please select...</option>
<option value="1">Summer</option>
<option value="2">Spring</option>
</select></li>
</ol>
<ol>
<li><label><span>Second</span></label>
<select name="block2" id="second">
<option value="0">Please select...</option>
<option value="1">Summer</option>
<option value="2">Spring</option>
<option value="3">Pink</option>
<option value="4">Corporate</option>
</select></li>
</ol>
<div id="value1">value 1</div>
<div id="value2">value 2</div>
<input type='button' onclick='changeText()' value='Calculate'/>
<div id="sum">Total here</div>
If anybody could help, that would be great. I really can't figure it out. Many many thanks!!