PDA

View Full Version : Function not working right in Internet Explorer only - loop and if statement



sec
06-09-2008, 03:38 AM
Hi,

The following is the jist of my function:

a call to checkString sends a string and checks it to see if it exists in an array (really an array of arrays):

Example: var stringArray = [ ['string1', 'stringPath', 'stringText'] ]

Then a loop goes through the array to check to see if stringArray[i][0] matches the value sent (e.g. 'string1')

if the strings match, it should return the value of stringArray[i][1] and stringArray [i][2] (e.g. 'stringPath' and 'stringText')

otherwise, it should return false.

This seems to work in everything but IE. It seems that the function will return the array if the if statement is met, but it does not return anything (e.g. false) if the if statement is not met.

however, if I hardcode the if statement to check, for example, stringArray[0][0] it works fine or even if 1==2. But obviously not what I need.

Any ideas? Things I could look into? Thank you!

Master_script_maker
06-09-2008, 12:47 PM
see if this works:

var stringArray = Array(Array('string1', 'stringPath', 'stringText'), Array('string2', 'stringPath2', 'stringText2'));
function arrayVal(string) {
for (var i=0; i<stringArray.length;i++) {
if (stringArray[i][0]==string) {
return Array('path'=>stringArray[i][1], 'text'=>stringArray[i][2]);
break;
}
return false;
}
}
so if var atts=arrayVal('string1');, atts['path']='stringPath' and atts['text']='stringText'