Jump to content

[SOLVED] Changing background image


matfish

Recommended Posts

Hi, Iv got the below code when clicking on an image in a list it changes the background of a div to that image. It simply uses numbers to identify the images,

 

This works fine in FF and IE7, but not IE6 which Im testing:

 

function change_image($id){
document.getElementById('pic_border').style.backgroundImage='url(image_assets/image'+$id+'.jpg)';
}

 

Any ideas why this may not work in IE6-

 

Many thanks

Link to comment
https://forums.phpfreaks.com/topic/49430-solved-changing-background-image/
Share on other sites

yup looks like you are mixing up php with javascript, lose the $.

 

I lifted this from my code, runs perfect in ie6 + ff:

document.getElementById('innergraphic').style.backgroundImage= 'url(' + or + ')'; 

-the 'or' is a javascript variable

 

try alerting the 'id' variable, maybe the code that creates it has a cross browser problem.  Also what is the coding of the item with id="pic_border", there can be cross browser compatablilies with the coding of stuff like that.  Like for instance, if it is actually coded name="pic_border", that will work with some browsers and not others.  Some browsers are more sensitive about using the same id= more than once as well.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.