artlake Posted October 8, 2006 Share Posted October 8, 2006 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 More sharing options...
scott100 Posted October 8, 2006 Share Posted October 8, 2006 I need a function to calculate the total price of these items and display the resultsI 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 More sharing options...
jhecht Posted October 9, 2006 Share Posted October 9, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now