using a variable in variable.lastIndexOf not working properly

by Chuck Evans <Chucke(at)captura.com>

 Date:  Wed, 12 Jan 2000 18:37:03 -0800
 To:  "'HWG Languages'" <hwg-languages(at)hwg.org>
  todo: View Thread, Original
I'm trying to use javascript to return the last position of a slash in a
URL:

<script language="JavaScript">
<!--
var loc_string = document.location;
var last_index = loc_string.lastIndexOf('/');
document.write(last_index);
//-->
</script>

Every time I load the page, though, I get the error: Object doesn't support
this property or method

If I replace loc_string with like with an actual string in quotes (second t
in http left of purposely to avoid making a real hyperlink):

var last_index = "htp://www.mypage.com/index.html".lastIndexOf('/');

Then it returns an index position correctly. Any idea what I'm doing wrong?
Shouldn't I be able to use variablename.lastIndexOf() after creating and
defining the variable?

FYI, ultimately, I want a function that will strip everything before the
last / in a URL so I can then replace it with a different URL. For example,
I want to be able to turn htp://www.mypage.com/directory/subdir/index.html
into htp://www.mypage.com/directory/otherdir/index.html.

Any guesses on how to do that would be appreciated too. Another way to do it
would be to find /subdir/ in the string and replace it with /otherdir/ but I
can't begin to work on that part of the function until I get the lastIndexOf
part working.

---------------------------------------------------------
Chuck Evans
Web Marketing Manager
Captura Software, Inc.
(425) 424-1155
chucke(at)captura.com
www.captura.com

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA

This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.