Jump to content

examples


artlake

Recommended Posts

pizza.htmlI am looking for an example so tha I can complete an assignment in a client and server side scripting class that I am taking. I need to be able to add totals of the prices of the check boxes and radio buttons on this page and display the results. The part that is completed is from the W3schools tutorial. I need to finish this so I can move onto a php assignment.
Link to comment
Share on other sites

This isn't very complicated, you just need to have a function on each radio button or checkbox that totals up the cost, and a place to display it. Instead of using an input text box to show things, just use a div. Make something like this:<div id="totalcost"></div>Where you want the cost to show up. You can apply a style to the div if you want to change the font formatting. Have the same function on each radio button or checkbox that goes through the form and adds up the cost.<input type="radio" name="size" onclick="calculate_total()" value="small"> etcAlso, you need a unique name for each of the checkboxes, don't call all of them "pizza". Make them something like this:<input type="checkbox" name="cheese" value="1">extra cheeseThe javascript function should look something like this:

function calculate_total(){  total = 0;  if (document.forms[0].size == "small")	total = 8;  if (document.forms[0].size == "medium")	total = 12;  if (document.forms[0].size == "large")	total = 16;  if (document.forms[0].cheese.checked == true)	total++;  if (document.forms[0].pepperoni.checked == true)	total++;  ...  document.getElementById("totalcost").innerHTML = "$" + total;}

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
×
×
  • Create New...