Click to See Complete Forum and Search --> : Please someone help with my code


DarryBoy
04-17-2003, 07:45 PM
I have the following code that presents an error. I have an else clause 3 times in a row. I know its wrong. Someone please help with my syntax.

function CheckChoice(whichbox)
{
with (whichbox.form)
{
//Handle differently, depending on type of input box.
if (whichbox.type == "radio")
{
//First, back out the prior radio selection's price from the TOTALQTY:
hiddenTOTALQTY.value = eval(hiddenTOTALQTY.value) - eval(hiddenpriorradio.value);
//Then, save the current radio selection's price:
hiddenpriorradio.value = eval(whichbox.price);
//Now, apply the current radio selection's price to the TOTALQTY:
hiddenTOTALQTY.value = eval(hiddenTOTALQTY.value) + eval(whichbox.price);
}
else
{
//If box was checked, accumulate the checkbox value as the form TOTALQTY,
//Otherwise, reduce the form TOTALQTY by the checkbox value:
if (whichbox.checked == false)
{ hiddenTOTALQTY.value = eval(hiddenTOTALQTY.value) - eval(whichbox.value); }
else { hiddenTOTALQTY.value = eval(hiddenTOTALQTY.value) + eval(whichbox.value); }
}
else
{
//If box was checked, accumulate the checkbox value as the form TOTALQTY,
//Otherwise, reduce the form TOTALQTY by the checkbox value:
if (whichbox.checked == false)
{ hiddensubtotal.value = eval(hiddensubtotal.value) - eval(whichbox.value); }
else { hiddensubtotal.value = eval(hiddensubtotal.value) + eval(whichbox.value); }
}

//Ensure the TOTALQTY never goes negative (some browsers allow radiobutton to be deselected):
if (hiddenTOTALQTY.value < 0)
{
InitForm();
}

//Now, return with formatted TOTALQTY:
return(formatCurrency(hiddenTOTALQTY.value));
}
}

DrDaMour
04-17-2003, 08:18 PM
this will be hard to debug because it's inherently flawed, and since there are no objects to test it against, do you have some html we can use to debug?

also you know that you should use

if(){
}
else if(){
}
else if(){
}
else{
}

for and if-then-else-if-then-else type tree.