Wondering if anybody would have an idea of how i can add the checked value of a checkbox to a calculation that includes radio buttons.
I have written the code that calculates the sum of 2 radio-button groups which looks like this;
<script>
var calculateCost = function() {
var radiobutton; // A radio button
var cost = 0; // Cost of the selected room
// Add up the cost of the selected rooms
for (var i = 1; i <= 3; i++) {
radiobutton = document.getElementById("type" + i);
if (radiobutton.checked == true) {
cost += parseInt(radiobutton.value);
}
}
for (var i = 1; i <= 3; i++) {
radiobutton = document.getElementById("ts" + i);
if (radiobutton.checked == true) {
cost += parseFloat(radiobutton.value);
}
}
alert("The cost of the room per night is $" + cost);
};
</script>
I also have a check-box which holds a value that needs to be added to the calculation if it is checked.
Have tried numerous different things but all have disabled the code for the radio-buttons.
Any advice is very appreciated.
Aucun commentaire:
Enregistrer un commentaire