Page 1 of 1

String.substr

Posted: Sun Mar 20, 2005 4:40 pm
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.

Posted: Sun Mar 20, 2005 4:50 pm
by feyd
first off, why isn't this a function? Next, I believe substr() takes 2 integers, not a string.

Posted: Sun Mar 20, 2005 5:01 pm
by xudzh
That's why. I've put it into string.

Posted: Mon Mar 21, 2005 4:52 am
by Calimero
as Feyd said.

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

try it.