replace method and array value

J

JAG

I am getting an error using the replace method in one of my functions.

I am using the replace method in the mail document function in my
frameset .hta to change forward slashes to back slashes in the myVar
string.

The myVar string is obtained in my show document function:
myVar = filename;

In my mail document function:
myVar = myVar.replace(/\//g,"\\");

This works as expected.

I have a history function that gets called when the back button is
clicked in my .hta. The myVar variable then gets its value from my
history array:
myVar = myLink[n].href;

When the mail document function is invoked and the replace method
called I get the error 'Object doesn't support this property or method'
on the replace line.

I have verified the myVar string both with and without using the
history function and both return identical strings (at least visually
in my alert dialog).

Does anyone know why the replace fails when myVar gets its value from
my history array? Must be something fundamental I'm missing but I can't
figure out what it is.

Thanks in advance for any help.
 
L

Lee

JAG said:
I am getting an error using the replace method in one of my functions.

I am using the replace method in the mail document function in my
frameset .hta to change forward slashes to back slashes in the myVar
string.

The myVar string is obtained in my show document function:
myVar = filename;

In my mail document function:
myVar = myVar.replace(/\//g,"\\");

This works as expected.

I have a history function that gets called when the back button is
clicked in my .hta. The myVar variable then gets its value from my
history array:
myVar = myLink[n].href;

When the mail document function is invoked and the replace method
called I get the error 'Object doesn't support this property or method'
on the replace line.

I have verified the myVar string both with and without using the
history function and both return identical strings (at least visually
in my alert dialog).

Apparently myVar is not a string.
My guess is that it's a Location object.
It will appear to be a string in an alert, because what you actually
see is the result of its toString() method.

myVar.toString().replace(...)


--
 
J

JAG

Lee said:
JAG said:
I am getting an error using the replace method in one of my functions.

I am using the replace method in the mail document function in my
frameset .hta to change forward slashes to back slashes in the myVar
string.

The myVar string is obtained in my show document function:
myVar = filename;

In my mail document function:
myVar = myVar.replace(/\//g,"\\");

This works as expected.

I have a history function that gets called when the back button is
clicked in my .hta. The myVar variable then gets its value from my
history array:
myVar = myLink[n].href;

When the mail document function is invoked and the replace method
called I get the error 'Object doesn't support this property or method'
on the replace line.

I have verified the myVar string both with and without using the
history function and both return identical strings (at least visually
in my alert dialog).

Apparently myVar is not a string.
My guess is that it's a Location object.
It will appear to be a string in an alert, because what you actually
see is the result of its toString() method.

myVar.toString().replace(...)


--

Your guess was correct, apparently. Adding toString() gave me the value
I was looking for. Thank you for the prompt help.

So my array value , which I assigned to myVar, is a location object.
Guess I've got some reading material tonight. Thanks again for your
help.
 

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,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top