Jump to content

add total


artlake
 Share

Recommended Posts

I need a function to calculate the total price of these items and display the results

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><title>pizza</title><style></style><script type="text/javascript">function check(size){document.getElementById("answer").value=size}function createOrder(){pizza=document.forms[0].pizzatxt=""for (i=0;i<pizza.length;++ i){if (pizza.checked){txt=txt + pizza.value + " "}}document.getElementById("order").value="You ordered a pizza with " + txt}</script></head><body><form> Pizza <p>Select size and toppings then click total </p><br> <input type=radio name="size"onclick="check(this.value)" value="small">small $8<br> <input type=radio name="size"onclick="check(this.value)" value="medium">medium $12<br> <input type=radio name="size"onclick="check(this.value)" value="large">large $16<br><p>Size <input type="text" id="answer" size="6"></p> <p>add $1 for each topping</p><input type="checkbox" name="pizza" value="extra cheese">extra cheese<br /><input type="checkbox" name="pizza" value="pepperoni">pepperoni<br /><input type="checkbox" name="pizza" value="sausage">sausage<br /><input type="checkbox" name="pizza" value="mushrooms">mushrooms<br /><br> <input type="button" onclick="createOrder()" value="Send order"><br /><br /><input type="text" id="order" size="70"></form> </body></html>
Link to comment
Share on other sites

I need a function to calculate the total price of these items and display the results
I have totalled up the toppings and sent an alert to screen, from that you should be able to figure out how to add the pizza size
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><title>pizza</title><style></style><script type="text/javascript">var total=0;var topping=1;function check(size){document.getElementById("answer").value=size}function createOrder(){total=0;pizza=document.forms[0].pizzatxt=""for (i=0;i<pizza.length;++ i){if (pizza[i].checked){txt=txt + pizza[i].value + " ";total+=topping}}alert("Total $"+total);document.getElementById("order").value="You ordered a pizza with " + txt}</script></head><body><form> Pizza<p>Select size and toppings then click total </p><br> <input type=radio name="size"onclick="check(this.value)" value="small">small $8<br><input type=radio name="size"onclick="check(this.value)" value="medium">medium $12<br> <input type=radio name="size"onclick="check(this.value)" value="large">large $16<br><p>Size <input type="text" id="answer" size="6"></p><p>add $1 for each topping</p><input type="checkbox" name="pizza" value="extra cheese">extra cheese<br /><input type="checkbox" name="pizza" value="pepperoni">pepperoni<br /><input type="checkbox" name="pizza" value="sausage">sausage<br /><input type="checkbox" name="pizza" value="mushrooms">mushrooms<br /><br> <input type="button" onclick="createOrder()" value="Send order"><br /><br /><input type="text" id="order" size="70"></form></body></html>

Link to comment
Share on other sites

i dont have time to look at the actual code itself, but for the love of god fix this:

<input type=radio name="size"onclick="check(this.value)" value="small">small $8<br><input type=radio name="size"onclick="check(this.value)" value="medium">medium $12<br><input type=radio name="size"onclick="check(this.value)" value="large">large $16<br>--- Change to----<input type="radio" name="size" onclick="check(this.value)" value="small">small $8<br/><input type="radio" name="size" onclick="check(this.value)" value="medium">medium $12<br/><input type="radio" name="size" onclick="check(this.value)" value="large">large $16<br/>

<br> is not acceptable by any validator, use <br/> instead

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...