View Full Version : *help* reading a filename using javascript

04-20-2005, 12:54 PM
hey peeps,

i'm currently looking at getting a script to read in a filename and select a style sheet for the page depending on the name.

so for example "blue_fish.gif" brings up a blue style or "red_herring.gif" brings a red style up.

One way which works is setting up two arrays one with the images loaded in and one with the css files in. however i'm finding it very messy especially when i want to update more pictures and add more styles.

so i was wondering if there is some way i can just look at the filename and then pick a style.


04-20-2005, 02:02 PM
Well you can use Javascript to switch styles if that's what you need?


04-21-2005, 12:35 PM
well hmm,

well i want the sheet to change depending on the name of an image.

So i'm wondering if i could parse the file name somehow, perhaps trying to do a hack job on the javascript cookie methods.

hope that clears it up a little,


04-21-2005, 12:52 PM
well i want the sheet to change depending on the name of an image.

and on what event do you want this to happen?

04-21-2005, 02:47 PM
i guess this would trigger when a user clicks a link to a specific section, i can see where you're going to with this tell me if i'm gone in the wrong direction, by setting it to change on an onClick() event, changing picture and stylesheet....at the same time..?

But i'm after something like the filename parser to make things simpler for a person to update. Meaning i'm not the only one updating the site i'm working on and i would like to make things easier for the other people putting stuff up. A simple rename this file to say BLU_main.jpg to bring a bluestyle sheet up would be superb to both myself and the people working with this.

i understand this would be a hell of a lot easier with php, but i don't have the luxury of a php, apache server. So i'm doing it old school... despite it being slow :(.

hope that hasn't confused you...



04-21-2005, 03:21 PM
If you are triggering it onclick, don't you already have to know what stylesheet to put there?

04-22-2005, 12:51 PM
i would like it to change it automatically, so when you load a page with a BLU_ in the image name in it picks the sheet like that. instead of setting it to change the sheet for each link and behaviour.



04-22-2005, 02:19 PM
so is this blue image constantly changing to a different image? Is it some type of random image script?

04-25-2005, 12:13 PM
i don't want it to just do blue images also want to set the styles to different schemes; red for a RED_img, green for a GRE_img, yellow for a YEL_img.

A random image would be nice, but i know that javascript won't populate arrays based on a file's contents. Hmmm would be nice that, then you could get it to just pick an image, then feed the img name into another script that picks up the tag... or use two arrays mirroring a style sheet with an image... [1]BLU_img --> second array--->[1]Blue.css, however this is easy for me..but for other folks..might be daunting :confused: .

i just don't know what to do anymore :(

..would be so much easier leaving it at a switch on click wouldn't it...