Click to See Complete Forum and Search --> : URLs


urxlnc
02-03-2003, 09:32 AM
Well I think this is kinda simple thing but its messing me up,

Well I have a javascript file in the base directory.... for example.

abc\myjavascript.js

and I have five directories in the base directory. for example

abc\xy\
abc\ab\
abc\mno\
abc\yz\
abc\rs\

I have files with names 1.html, 2.html.... 12.html...114.html...

All files are marked with number and there are also files in triple digits

All the five directories
xy\
ab\
mno\
yz\
rs\
have the files 1.html.....444.html.... but with different versions.

i have a drop down menu in all the files in all the directories.
suppose, from the page of

abc\xy\3.html

if I choose mn version (from the list) the file to be loaded should be

abc\mno\3.html

Now I am almost done with the javascript but the problem thats is happeneing is,

when I choose mno version from

abc\xy\3.html

the file loading is

abc\xy\mno\3.html

where I want

abc\mno\3.html

I am using this script for that

var url = "mno/" + fileName ;
document.location.href = url;

What should I do? use substring to get the current location using document.location;

or is there any way to go down the directory tree from javascript?

and if i should use the substring, can anyone give me the syntax?

Also, I have problems finding the file name, as the file names differ in size... in the same directory the file names are from 1.html to 444.html how can I use substring function to get only the file name, either 1.html or or 23.html or 444.html


Thanks.

Zach Elfers
02-03-2003, 09:35 AM
Use an absolute url such as http://www.yoursite.com/abc/mno/3.html

urxlnc
02-03-2003, 09:37 AM
Thanks, I thought about it, but I don't want to put it that way, is any any way I can go down one step down in the directory tree?

urxlnc
02-03-2003, 09:43 AM
hehehe... sorry but I got it :)

instead of


var url = "mno/" + fileName ;
document.location.href = url;


I used...


var url = "../mno/" + fileName ;
document.location.href = url;


but still a problem remains...

to find the name of the file... coz 3.html will direct to 3.html in other directory... and 444.html will direct to 444.html in other directory.

urxlnc
02-03-2003, 12:01 PM
Hey I kinda got it, but can anyone modify this code? Its working but its too pron to errors, or I think so,

function gotoVersion(){
var loc = document.location;
var locvalue = '';
locvalue +=loc;
var fileName = '';
fileName += findname(locvalue);
var listBox = document.form1.verList;
var index = listBox.selectedIndex;
var verType = listBox[index].value;
findVer(verType,fileName);
}

function findname(loc){
var locLen=loc.length;
var slashValue ;
var fileName='';
while(slashValue!=0) {
slashValue = loc.indexOf("/");
slashValue += 1;
loc = loc.substring(slashValue, locLen);
}
return loc;
}

Please give your comments.
Thanks