String.substr

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
xudzh
Forum Commoner
Posts: 48
Joined: Sat Feb 19, 2005 6:22 pm

String.substr

Post by xudzh »

Ok, this javascript gives me truoble.

Code: Select all

javascript:var theTags = document.getElementsByTagName('a');  for (x=0;x<1;x++) {y=theTags&#1111;x].href;var z=y.substr('2,8');alert(z); } void 0;
I tried to get 3rd-10th character of the href.
HOwever everytime z is the full url. substr() never worked.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

first off, why isn't this a function? Next, I believe substr() takes 2 integers, not a string.
xudzh
Forum Commoner
Posts: 48
Joined: Sat Feb 19, 2005 6:22 pm

Post by xudzh »

That's why. I've put it into string.
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

Post by Calimero »

as Feyd said.

substr(2,8 ) should do it - not substr('2,8');

try it.
Post Reply