Why don't this javascript work?

Why don’t this work?

function write(){
writeOutPath("td");/*Don't work to pass arguments this way?*/
}


function writeOutPath(theSearchWord){
var theUrlToGoTo = "";
var currentUrl = window.location.href;
var aPosition = currentUrl.indexOf(theSearchWord); /*This becomes undefined, why???*/

for(i=0; i< aPosition.length;i++){
theUrlToGoTo=(theUrlToGoTo +  currentUrl.charAt(i));
}
document.getElementById('testning').innerHTML =theUrlToGoTo + aPosition.length;
/*window.location("www.hulenet.se");*/
}

[QUOTE]
var aPosition = currentUrl.indexOf(theSearchWord); /This becomes undefined, why???/

[QUOTE]
That’s not undefined, but it returns a Number not an object with a length property. This is what is invalid:


for(i=0; i< aPosition.[B]length[/B];i++){

Should be


for(i=0; i< aPosition ;i++){

Probably best to look at the substr() and substring() methods of the String object as an alternative.