PDA

View Full Version : split() doesn't work


Michiel
08-23-2003, 01:44 PM
Hi,

I'm using the followig javascript to get the name + extension of the current page, without the complete path:


var the_url = document.location;
var url_array = the_url.split("/");
var last =url_array.lenght - 1;
alert(last);
value = second_split[last];
alert(value);


Somehow this code doesn't work. I get the error that the object doesn't support this method. Where do I go wrong?

Thanx in advance, Michiel

fredmv
08-23-2003, 03:41 PM
I think this may be causing your problem:


var last =url_array.lenght - 1;


Fix that and it should work. :thumbsup:

Also - Where is the variable "second_split" defined?

Vincent Puglia
08-23-2003, 06:22 PM
Hi,

In addition to Fred's comment on the typo, 'document.location' is an object. Objects do not have split(...) as a method. What you want is a string.


var the_url = "" + document.location;


Vinny

Michiel
08-23-2003, 11:53 PM
Thanx guys,

it works just fine now!

>> Also - Where is the variable "second_split" defined?

second_split is kind of the remains of an earlier version of the script. Thanx for noticing! It is cool to know that you guys are realy interested in helping someone.

Cheers, Michiel