Hi guys,
I'm trying to create a dynamic order form with multiple selects, each one containing different product add-on with its individual price. After selecting each add-on I want a price to change dynamically. I've managed to create 1 select that is updating the price as it should, but I don't know how can I have more of them. Here is my code so far:
HTML:
But when I'm trying to add another select it breaks the whole thing. Any ideas please?
I'm trying to create a dynamic order form with multiple selects, each one containing different product add-on with its individual price. After selecting each add-on I want a price to change dynamically. I've managed to create 1 select that is updating the price as it should, but I don't know how can I have more of them. Here is my code so far:
Code:
function recalculate(formObj) { var total = 200; for (var i=0; i<formObj.item.length; i++) { var myItem = formObj.item[i]; if (myItem.selected) { total += parseFloat(myItem.value); } } formObj.total.value = total; }
Code:
<form method="post" name="order" action="order.php" onsubmit="return false;"> <label for="topper">Topper</label> <select name="item" id="topper" onchange="recalculate(this.form)"> <option value="0">No topper</option> <option value="35">Novelty Bride & Groom Set (+€35.00)</option> <option value="20">Waltzing B&G (+€20.00)</option> <option value="20">Jewellery Black (+€20.00)</option> </select> <p> Total: € <input type="text" name="total" id="total" size="10" value="200.00"> </p> </form>
But when I'm trying to add another select it breaks the whole thing. Any ideas please?
Comment