Can't get a substr() or substring() of a passed in variable

D

Daniel Reardon

All,

I'm sure that this is an old question, but I'm having problems getting
a substring of a passed in variable. I can do other string
manipulation with it such as concatonation, but I'm really trying to
get everything after the = assigned to the id variable (i.e. set MSFT
to the id variable). Any help would be appreciated it.


'ticker' variable passed in is =
'http://caps.fool.com/Ticker.aspx?source=icaedilnk9950012&ticker=MSFT''

The first alert(ticker) work perfect and returns the entire string
above.

####Non-Working
Example####________________________________________________
function enhanceTickerLinks(ticker)
{
alert(ticker)
var id
id = ticker.substr(5)
alert(id)
 
R

Richard Cornford

David said:
That's because the parameter you're using is wrong.

String.substr(start, length)

if argument length is missing, it's assumed to be the
length of the string

The second argument to - substr - is optional.
Firefox accepts negative indices to read from the end of
the string, but IE isn't that advanced.
<snip>

IE does not appear to have any problems with - substr - only being given
one argument.

The most likely explanation here is that the question as asked is
substantially misleading and rather than being passed a string as its
argument the function is being passed a reference to the - location -
object, which does have a - toString - method (so will show the URL text
with - alert(location) - and may be concatenated to strings using the -
+ - operator) but dos not have - substring - or substr - methods.

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,630
Members
45,335
Latest member
Tommiesal

Latest Threads

Top