views:

291

answers:

4

I have this daily image rotation script, which works great. I need the images to be clickable though. Any help is appreciated.

<!-- Begin
today = new Date();
day = today.getDay();
arday = new Array
("http://www.magnatexpumps.com/imagesnew/featured/featuredProduct_3575.jpg", 
"http://www.magnatexpumps.com/imagesnew/featured/featuredProduct_mp_mpl.jpg", 
"http://www.magnatexpumps.com/imagesnew/featured/featuredProduct_mph.jpg", 
"http://www.magnatexpumps.com/imagesnew/featured/featuredProduct_mmp.jpg", 
"http://www.magnatexpumps.com/imagesnew/featured/featuredProduct_mep.jpg", 
"http://www.magnatexpumps.com/imagesnew/featured/featuredProduct_mst.jpg",
"http://www.magnatexpumps.com/imagesnew/featured/featuredProduct_s.jpg", 
"http://www.magnatexpumps.com/imagesnew/featured/featuredProduct_maxp.jpg", 
"http://www.magnatexpumps.com/imagesnew/featured/featuredProduct_mpt.jpg",
"http://www.magnatexpumps.com/imagesnew/featured/featuredProduct_mta.jpg", 
"http://www.magnatexpumps.com/imagesnew/featured/featuredProduct_me.jpg",
"http://www.magnatexpumps.com/imagesnew/featured/featuredProduct_sm.jpg");

document.write("<img src='" + arday[day] + "'>");
//  End -->
</SCRIPT>
A: 

Why don't write an <a> element as well?

document.write('<a href="LINK_HERE" title="TITLE_HERE"><img src="' + arday[day] + '"><\/a>');
LiraNuna
A: 

Clickable to where?? You've got to add a url to each "row" in addition to the img src.

Eg instead of each row being just "http://www.magnatexpumps.com/imagesnew/featured/featuredProduct_3575.jpg", do instead:

{ img: "http://www.magnatexpumps.com/imagesnew/featured/featuredProduct_3575.jpg",
  url: "LINK GOES HERE" },

Then the last line can do:

document.write('<a href="' + arday[day].url + '"><img src="' + arday[day].img + '" /></a>');
Roatin Marth
I want to thank everybody that helped. I was able to make it work and I don't do programming so that says something :o) Here it is in action: magnatexpumps.com/index.html a script that changes images every day at midnight and is also clickable. Thank you very much.
A: 

The example below creates a link around your image, hjust change the href attribute's value :

document.write("<a href='#'><img src='" + arday[day] + "' border='0'></a>");
Canavar
A: 

Few general tips:

  • Always declare your variables (var today = ..., not just today = ...)
  • Drop new Array in favor of more concise (and just as compatible these days) "[" and "]" syntax.
  • Don't repeat host name in array of links. It's a maintenance nightmare and a waste of bandwidth.
  • Drop HTML comments from within your script contents. Browsers that need them are obsolete by now.
  • Always provide "alt" attribute on your images. When you wrap them with anchor, don't forget to give title to anchor.
kangax