glibber
10-27-2004, 01:28 AM
The following function works fine until it hits the IF statement, at which point Mozilla stops dead in its tracks and says "IF is not defined". For the life of me, I can't see why. Everything's inside the function, so I can't be running afoul of any global/local definition-conflict issues. In addition, all the variables have been defined before the scripting engine gets to the IF, and they're all the same data type (string):function fWYH()
{
var vUrl = prompt ("Enter a URL","");
var vFirstseven = vUrl.substring(0,7);
vFirstseven = vFirstseven.toLowerCase();
var vHttp = "http://";
var vfixedUrl = "";
If (vFirstseven != vHttp)
{
vfixedUrl = vHttp + vUrl;
}
return vfixedUrl;
}
I'm not interested in finding another solution--I already know of an alternate solution using two functions instead of one. What I want to know is what's the $*%@#! up with this code in particular. I just can't see why it doesn't work (I know, my non-compsci background is showing). Is this a gotcha with JavaScript or with Mozilla, or is there some genuine ECMA-262 theoretical reason for this behavior?
TIA,
Mike
{
var vUrl = prompt ("Enter a URL","");
var vFirstseven = vUrl.substring(0,7);
vFirstseven = vFirstseven.toLowerCase();
var vHttp = "http://";
var vfixedUrl = "";
If (vFirstseven != vHttp)
{
vfixedUrl = vHttp + vUrl;
}
return vfixedUrl;
}
I'm not interested in finding another solution--I already know of an alternate solution using two functions instead of one. What I want to know is what's the $*%@#! up with this code in particular. I just can't see why it doesn't work (I know, my non-compsci background is showing). Is this a gotcha with JavaScript or with Mozilla, or is there some genuine ECMA-262 theoretical reason for this behavior?
TIA,
Mike