471,873 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,873 software developers and data experts.

Passing an image name as an argument


I would like to be able to open a web page and pass it the name of the picture that I want displayed. For example, the current line that displays the picture reads

<td width="762" bgcolor="#FFFFFF"><img src="165_6593.jpg" alt="" name="" width="760" height="570" border="0" /></td>

Each of the images that I want to display are the same size, so all I'm concerned with is being able to change the name of the image when I call the page. For example, if the page is called www.dandare.com and I want it to display the image dan.jpg then I'd like to call it using:

dan.jpg would then be substituted for "165_6593.jpg"

This is probably easy, but I did my IT degree in 1990 when DOS was king!

Thanks in advance...
May 24 '07 #1
2 1414
1,208 Expert 1GB
put this at the bottom of your html page
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. window.onload = setImage();
  3. function setImage() {
  4. var theimg = document.getElementById("img1");
  5. var winloc = window.location.href;
  6. var qstring = winloc.split("?")[1];
  7. var qimg = qstring.split("=");
  8. if (qimg[0]=="img") { theimg.src = qimg[1]; }
  9. }
  10. </script>

then try it out like this


or www.wherever.com?img=dan.jpg
May 24 '07 #2
Thanks- that's fantastic and worked first time!
May 25 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by domeceo | last post: by
7 posts views Thread by Harolds | last post: by
17 posts views Thread by Charles Sullivan | last post: by
4 posts views Thread by B Squared | last post: by
4 posts views Thread by tshad | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.