Click to See Complete Forum and Search --> : document.write specified text based on which file is loaded


debsweb
01-16-2003, 06:48 PM
I've got a floating menu working for a web site that I'm building. With the floating menu, they also want the short version of the page title displayed. I'm sure this can be done using Javascript so I don't have to create a separate menu.js file for each page (defeating the purpose of the darn thing in the first place).

I found this code to get the filename:
var filename = window.location.href;
filename = filename.substr(filename.lastIndexOf("/") + 1);

It works just as expected. Now I tried to write IF statements, then IF and ELSE statements, then even WHILE statements, but I just cannot get it to "document.write(text) if filename == xyz.html. I've got 8 pages on this site so far, so I need to have the script write the specified text when the current file displayed.

Example:
if (filename = "xyz.html") {document.write('.: XYZ Main :.');}
if (filename = "abc.html") {document.write('.: About Us :.');}
if (filename = "def.html") {document.write('.: Contact :.');}
..... and so on .....

If anyone can help with how I can get this to work, I'd be very grateful!

Thanks

AdamBrill
01-16-2003, 07:13 PM
Try making sure that the filenames are EXACTLY that. Maybe they are like xyz.htm instead of xyz.html or something like that. You could put an alert in there to see exactly what is in the filename variable is just before it checks. It has to be capitalized the same and everything to work.

debsweb
01-16-2003, 08:02 PM
Thanks, but I've been there and done that (I copied/pasted the file names into the script file). What the code above displays when run in the browser is this:

.: XYZ Main :.
.: About Us :.
.: Contact :.

<<<MENU HERE>>>

It displays all the text - not just the one that corresponds to the file name.

Do these have to be some type of if-else or while statements? I'm gonna keep playing around with different ways and orders of commands. If I find something that works, I'll post here in case anyone else needs it.

Although I'd still accept help on this.

debsweb
02-01-2003, 10:15 AM
Thanks Dave!!!

I popped in today to post that I had figured out my error in the syntax and saw that you posted the same answer. I must have inadvertently turned off the email notification thing somehow because I didn't get notified of your post.

It's just aggrivating when the simplest little error/oversight is the cause of my problems!

Again thanks for the help - everything is working great now. I was glad to see your answer there knowing that I did fix it correctly.

All I have to do now is wait for these guys to finalize what they want on their site and I can post the URL for all to see.

Deb