I've been trying to write a reasonably simply cost calulator, based on two levels of service, and a price drop the more of an item you purchase. When you hit submit the calculate() function should execute. I hate working with javascript because very often nothing happens! I just don't seem to be able to reassign values to variables and work with them. I get no error, nothing! Out of all the languages I've used javascript always has me stumped! Can anyone tell me why this doesn't work?
var servicelvl = document.calc.service.value;
var boxnum = document.calc.boxno.value;
var perbox;
alert("e;Service Level :"e;+servicelvl+"e;\nBoxnum :"e;+boxnum);
and check you are getting the values you expect. I am assuming that "calc" is your form name ?
This will only work in IE, since Netscape accesses the DOM in a different manner.
I also don't think that the case statements take conditionals. Thus it is completely ignoring case(boxnum > 0 && boxnum <=55): and going straight to default. Try using if/if else statements.
If this is the only function you've got in your script tags you'll need to close the function with a '}' closing curly brace.
I checked in NS 4.76 and it does not function correctly but in NS 7.01 it does. So it must be later versions that accept the more logical DOM. Thanks, CoderGob.
Thanks for those tips. When I wrote a much simpler test for the script I found I had to use eval() for the calculation to happen, but I will try it again.
Also, why won't case statements take conditionals? The same script worked in PHP