-
count id's using js.
I have made a simple script that uses checkboxes and textareas.
costumers can type a number in the textarea.
the value of the checkbox is multiplied with the number entered in the textarea.
The outcome is given at 'prijsbepaling' on the bottom,
there is only one problem..
the 'id:total' also at the bottom of the script only counts the value of the checked checkboxes, and not the multiplied outcome..
does anybody know how it would be possible to count
calzone
middel
groot
and display it in 'id: total' ?
Thnx!
Code:
if(!document.getElementById && document.all)
document.getElementById = function(id){ return document.all[id]}
var calzone = 0;
var middel = 0;
var groot = 0;
var total = 0;
function update(checkbox){
if(checkbox.checked){
total += parseFloat(checkbox.value);
} else {
total -= parseFloat(checkbox.value);
};
document.getElementById("total").innerHTML = "€ " + total.toFixed(2).replace(".", ",");
};
<!-- functie voor het verbergen van een element -->
function showHide (id)
{
var style = document.getElementById(id).style
if (style.visibility == "hidden")
style.visibility = "visible";
else
style.visibility = "hidden";
}
<!-- vermenigvuldigen -->
function multiply(value, multiplier, outputId) {
document.getElementById(outputId).innerHTML = "€ " + value * multiplier + ",-";
}
Code:
<tr><td><input type="checkbox" value="3" onclick="showHide('calzone1');update(this);"></input></td><td>€ 3,00</td>
<td>
<div id="calzone1" style="visibility: hidden;">
<input name="hoeveelheid" type="text" onkeyup="multiply(this.value, 3, 'calzone')" id="hoeveelheid" size="2" maxlength="2">
<label for="hoeveelheid">Maal</label></div>
</td></tr>
<tr><td><input type="checkbox" value="4.00" onclick="showHide('middel1');update(this);"></input></td><td>€ 4,00</td>
<td>
<div id="middel1" style="visibility: hidden;">
<input name="hoeveelheid" type="text" onkeyup="multiply(this.value, 4, 'middel')" id="hoeveelheid" size="2" maxlength="2">
<label for="hoeveelheid">Maal</label></div>
</td></tr>
<tr><td><input type="checkbox" value="5.00" onclick="showHide('groot1');update(this);"></input></td><td>€ 5,00</td>
<td>
<div id="groot1" style="visibility: hidden;">
<input name="hoeveelheid" type="text" onkeyup="multiply(this.value, 5, 'groot')" id="hoeveelheid" size="2" maxlength="2">
<label for="hoeveelheid">Maal</label></div>
</td></tr>
<!-- prijsbepaling -->
<tr><td></td><td><b>Calzone:</b></td><td id="calzone">€ 0,00</td></tr>
<tr><td></td><td><b>Middel:</b></td><td id="middel">€ 0,00</td></tr>
<tr><td></td><td><b>Groot:</b></td><td id="groot">€ 0,00</td></tr>
<tr><td></td><td><b>Totaal:</b></td><td id="total">€ 0,00</td></tr>
-
This is a Java forum; your question is about JavaScript; both languages don't have much in common, sorry.
kind regards,
Jos