Solved

How do i display an image in Javascript using a wildcard for the image name?

Posted on 2008-06-12
5
356 Views
Last Modified: 2012-05-05
Hello,

I want to display an image in Javascript from a folder which is named after a record 'id' and the name of the image is prefixed by X_

I have made the following guess as to what this might be - please can you correct?
<img src="travel_pics/" + id + "/X_*.jpg" width=150 height=100>


Many thanks
0
Comment
Question by:Daniish
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 21767217
If there are more then one files that match the wild card then which file should the browser display?
0
 

Author Comment

by:Daniish
ID: 21767236
I will ensure that there is only ever 1 file that is prefixed X_ in each folder.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 21768111
Sorry but even then, JavaScript cannot look at web server side file system.
Browser is allowed only to ask for one file and gets that one files as response.

You have to script that on web server side by ASP, PHP or whatever scripting you use on server side.

0
 

Author Comment

by:Daniish
ID: 21768361
It shouldn't need to look at the web server side file system - because the filename is composed of attributes already available in my PHP script - namely the 'id' that are alredy being displayed on my site...

Really all i'm asking is how to use a wildcard in a filename:

"/X_*.jpg"

whether that be
"\X_" . * . ".jpg" - will the asterix work here ?
0
 

Accepted Solution

by:
Daniish earned 0 total points
ID: 21769000
My bad!

Since there is only ever going to be one image in a folder that is prefixed X_ i may as well give the image a complete name e.g. XXX.jpg and do the same for all folders, that way there's no need for a wildcard anyway.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question