PDA

View Full Version : Frustrating..WHY AM I getting this error: * is not a function...when?



BrightNail
Nov 26th, 2002, 08:14 AM
hey all,

okay..I worked out some solutions to all my questions...heheheheh..

anyways...I am using the split function in some of my functions and it works great...BUT, in a particular function, it craps out....even if I want to do a "indexOf()"...it craps out....here is the code that generates the error:

function changeNonprice(sNum,whichSel){
if(sNum == 0){}else{
var compareThis = document.chkOut[whichSel].options[sNum].text;
for(y=0;y<TotalMaps.length;y++){
for(z=0;z<eval('Map'+y).length;z++){
var compareWith=eval('Map'+y)[z];
var searchFor = compareWith.split(":");
alert(compareWith)//{
// }
}
}
}
}

I've tried using SPLIT, INDEXOF...etc...and I do alerts for testing, and the values are all good..ie...

compareWith
compareThis
Map + y

etc...these all give me the appropriate array values and such...

BUT WHEN I try to splice or using the indexOf..I get this error..

compareWith.split is not a function.

why?.....the code below works great and DOES NOT generate any errors:

function populateAdditional(pricelevel){
document.chkOut.additional.options.length=0;
if(pricelevel[3].length == ""){
document.chkOut.additional.options[0]=new Option('BEST AVAILABLE','BEST AVAILABLE')
document.chkOut.additional.options.disabled=true;
}else{
for (i=0;i<pricelevel[3].length;i++){
var resultadd=pricelevel[3][i].split(":");
document.chkOut.additional.options[i]=new Option(resultadd[1],resultadd[0])
document.chkOut.additional.options.disabled=false;
}
}
}

glenngv
Nov 26th, 2002, 08:35 AM
as I understand you have several array named MapN.
ok try this:



function changeNonprice(sNum,whichSel){
var compareWith,searchFor,arr;
if(sNum == 0){}
else{
var compareThis = document.chkOut[whichSel].options[sNum].text;
for(y=0;y<TotalMaps.length;y++){
arr = eval('Map'+y);
for(z=0;z<arr.length;z++){
compareWith=arr[z];alert(z+":"+compareWith);
searchFor = compareWith.split(":");
//...
}
}
}
}