J
John
Can any advise on why the SWITCH block of code doesn't work.
When its called, it always by-passes all the CASE parts and picks up the default value of 14.99
Any help would be appreciated.
<script language="javascript" type="text/javascript">
function calculatecost() {
var rockets=eval(document.forms[0].Rocket_Qty.value);
var fairies=eval(document.forms[0].Fairy_Qty.value);
var postage;
var costperitem;
var totalitems=rockets+fairies;
switch (totalitems) {
case (totalitems>19):
costperitem=6;
break;
case ((totalitems>14) && (totalitems<20)):
costperitem=6.50;
break;
case ((totalitems>9) && (totalitems<15)):
costperitem=7;
break;
case ((totalitems>4) && (totalitems<10)):
costperitem=7.50;
break;
default: costperitem=14.99;
}
if (document.forms[0].ordertype.options[1].selected) postage=2;
else postage=4.95;
if (totalitems<=0) document.forms[0].totalcost.value=0;
else
document.forms[0].totalcost.value=(totalitems*costperitem+postage).toFixed(2);
}
</script>
When its called, it always by-passes all the CASE parts and picks up the default value of 14.99
Any help would be appreciated.
<script language="javascript" type="text/javascript">
function calculatecost() {
var rockets=eval(document.forms[0].Rocket_Qty.value);
var fairies=eval(document.forms[0].Fairy_Qty.value);
var postage;
var costperitem;
var totalitems=rockets+fairies;
switch (totalitems) {
case (totalitems>19):
costperitem=6;
break;
case ((totalitems>14) && (totalitems<20)):
costperitem=6.50;
break;
case ((totalitems>9) && (totalitems<15)):
costperitem=7;
break;
case ((totalitems>4) && (totalitems<10)):
costperitem=7.50;
break;
default: costperitem=14.99;
}
if (document.forms[0].ordertype.options[1].selected) postage=2;
else postage=4.95;
if (totalitems<=0) document.forms[0].totalcost.value=0;
else
document.forms[0].totalcost.value=(totalitems*costperitem+postage).toFixed(2);
}
</script>