View Full Version : JavaScript If Statements

07-08-2003, 04:38 AM
I'm having trouble with my If Statements not working. The syntax is correct according to many sources. Do you think it could be the browser? Maybe there is a patch for this. Please respond if you have had similar problems. Thank you for any suggestions.

07-08-2003, 04:54 AM
show us some code?

07-08-2003, 06:00 AM
Here is an example of one of my If statements that does not work. If I type a value other than 0, 1, or 2 the alert should pop up, but it doesn't. Any suggestions?

function APGAR() {
if(field.value==0 || field.value==1 || field.value==2) {
var A=eval(document.REG.ACT.value);
var P=eval(document.REG.PULSE.value);
var G=eval(document.REG.GRIMACE.value);
var AP=eval(document.REG.APP.value);
var R=eval(document.REG.RESP.value);
} else {
alert("You must enter a 0, 1, or 2");

07-08-2003, 09:44 AM
hm...shouldn't be here somewere something like var somevalue= newString(); ? I think that math values and string characters are not the same thing...

07-08-2003, 10:45 AM
Think Kor's got it there, forms return strings so you need to turn it into number format so your code will now be

var theVal = parseInt(field.value, 10);
if (theVal >= 0 && theval <= 3) {