HELP: Why won't this javascript work?

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>
 
S

Steve Easton

Case is a reserved word in some scripting / programming languages.
Try using another word instead of Case and see if it makes a difference.


--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top