matfish Posted May 1, 2007 Share Posted May 1, 2007 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 Quote Link to comment Share on other sites More sharing options...
fenway Posted May 1, 2007 Share Posted May 1, 2007 I'm fairly sure that the path has to be quoted as well.. Quote Link to comment Share on other sites More sharing options...
mainewoods Posted May 2, 2007 Share Posted May 2, 2007 actually you don't quote the path fenway. I'm wondering what those $ are in $id? That's not a valid javascript variable. Quote Link to comment Share on other sites More sharing options...
matfish Posted May 2, 2007 Author Share Posted May 2, 2007 Am I mixing up php with JS? You mean I do not need the $id (just id)? Putting in the whole image path didt make any difference. Dont understand why it works with FF/IE7 but not IE6/5 Quote Link to comment Share on other sites More sharing options...
mainewoods Posted May 2, 2007 Share Posted May 2, 2007 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. Quote Link to comment Share on other sites More sharing options...
matfish Posted May 8, 2007 Author Share Posted May 8, 2007 Mainewoods, this worked a treat in all browsers. Many thanks Quote Link to comment Share on other sites More sharing options...
mainewoods Posted May 9, 2007 Share Posted May 9, 2007 good luck Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.