Question by ncp905: Does anyone know how to fix this javascript file?
I’m working on the below javascript page and everything works but the area that collects the pizza toppings checkboxes that are =true and puts the topping prices into the toppings variable. I keep getting an error saying that ‘checkboxes’ is undefined. Does anyone know how to fix this? Also is there anywhere on the web where I can debug this script so I would know the the line that’s truly causing the error? IE7 tends to point to the wrong lines when there’s an error whether runtime or syntax.
Thanks
————————————————————————–
function pizzaCalc()
{ var name = ""; var size = 0; var toppings = 0.00; var totToppings = 0.00; var crust=0; var total=0.00; var crustFlag = 0; var dspNameMsg =""; var dspTypeMsg = "";
objCheckBoxes= document.forms.frmPizza.elements["chkOptions"]; objRadioButtons= document.forms.frmPizza.elements["optCrust"];
name=document.frmPizza.txtName.value;
if (name=="")
{ dspNameMsg = "-a valid name.\n"; }
var numButtons = objRadioButtons.length;
for (var i =0; i if ( crustFlag != 1)
{
dspTypeMsg = "-a crust type.\n"; } if (name !="" && crustFlag ==1 )
{ size= parseFloat(document.frmPizza.cboPizzaSize.value); /*var numBoxes = objCheckBoxes.length;
for ( var i = 0; i < numBoxes; i++)
{
if (objCheckBoxes[i].checked == true)
{
toppings= parseFloat(objCheckboxes[i].value);
totToppings = parseFloat(totToppings)+ parseFloat(toppings); }
} alert(size);
alert(crust);
alert(toppings);
total = parseFloat(size) + parseFloat(crust) + parseFloat(totToppings); alert ("Here is your total,"+ name + ": $"+ total); } else
{
alert(" You must correct the following:\n"+dspNameMsg +dspTypeMsg);
} }
Best answer:
Answer by §©®Î¶†?®
I re-worked your form and your JavaScript. Since Y!A won't let me send all of the code, I'll post it here:
http://scriptar.com/JavaScript/pizza.html
Your checkboxes should be uniquely named because more than one can be chosen. When you submit the form, check for each checkbox's existence instead of a sending a particular price (or else you won't know what the user picked). You should try to avoid using tables for non-tabular data. Try using definition lists and fieldsets with CSS for a better form layout. Also, always use label tags for increased usability.
Give your answer to this question below!









