I'm trying to make an order form that adds up the values that are selected from different widget types, on submit there is no output. I'm not sure if I'm doing this right or if I'm going in the wrong direction? Is the way I'm trying to select the value actually working with the if statements, or is there another way to select the value?
var size = document.getElementById('pizzaSize').value;
if (document.getElementById('pepperoni').selected) {
var pepperoni = 1.50;
}
if (document.getElementById('mushrooms').selected) {
var mushrooms = 1.50;
}
if (document.getElementById('peppers').selected) {
var peppers = 1.50;
}
if (document.getElementById('pesto').selected) {
var pesto = 2.00;
}
function totalPizza() {
var total = parseInt(size + pepperoni + mushrooms + peppers + pesto);
var tax = parseInt(total * '.10');
var totalPlusTax = parseInt(total + tax);
document.getElementById("total").innerHTML = "Subtotal: " + total;
document.getElementById("tax").innerHTML = "Sales Tax: " + tax;
document.getElementById("totalTax").innerHTML = "Total: " + totalPlusTax;
}
<h2 id="heading">Pizza Order Form</h2>
<form id="pizzaOrder" action="#">
<label for="name">Name</label><br>
<input placeholder="First Last" type="text" name="name" id="name" minlength="5" maxlength="30"><br><br>
<label id="pizzaSize" for="size">Pizza Size</label><br>
<input name="size" type="radio" id="size" value="4">Personal<br>
<input name="size" type="radio" id="size" value="6">Small<br>
<input name="size" type="radio" id="size" value="8">Medium<br>
<input name="size" type="radio" id="size" value="10">Large<br>
<br>
<label for="crust">Crust Type</label><br>
<select id="crust" name="crust">
<option value="thin">Thin</option>
<option value="regular">Regular</option>
<option value="pan">Pan</option>
<option value="stuffed">Stuffed</option>
</select>
<br><br>
<label for="toppings">Toppings:</label><br>
<label for="pepperoni">Pepperoni</label>
<input type="checkbox" id="pepperoni" name="toppings" value="1.50"><br>
<label for="mushrooms">Mushrooms</label>
<input type="checkbox" id="mushrooms" name="toppings" value="1.50"><br>
<label for="peppers">Green Peppers</label>
<input type="checkbox" id="peppers" name="toppings" value="1.50"><br>
<label for="pesto">Pesto</label>
<input type="checkbox" id="pesto" name="toppings" value="2"><br>
<br><button type="submit" onsubmit="totalPizza();">Place Order</button>
</form>
<p id="total"></p>
<p id="tax"></p>
<p id="totalTax"></p>
Thank you for any suggestions.