/    Sign up×
Community /Pin to ProfileBookmark

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.

abcmyjavascript.js

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

abcxy
abcab
abcmno
abcyz
abcrs

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

abcxy3.html

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

abcmno3.html

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

when I choose mno version from

abcxy3.html

the file loading is

abcxymno3.html

where I want

abcmno3.html

I am using this script for that

[COLOR=red]var url = “mno/” + fileName ;
document.location.href = url;[/COLOR]

What should I do? use substring to get the current location using [COLOR=red]document.location;[/COLOR]

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.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Zach_ElfersFeb 03.2003 — Use an absolute url such as http://www.yoursite.com/abc/mno/3.html
Copy linkTweet thisAlerts:
@urxlncauthorFeb 03.2003 — 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?
Copy linkTweet thisAlerts:
@urxlncauthorFeb 03.2003 — hehehe... sorry but I got it ?

instead of

[COLOR=red]

var url = "mno/" + fileName ;

document.location.href = url;

[/COLOR]


I used...

[COLOR=red]

var url = "../mno/" + fileName ;

document.location.href = url;

[/COLOR]


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.
Copy linkTweet thisAlerts:
@urxlncauthorFeb 03.2003 — 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
×

Success!

Help @urxlnc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...