PDA

View Full Version : [JS] bg change help pls



MrCraig
23-12-2008, 04:11 PM
Hey,

Im wanting to change the background image of a cell with javascript and have got



function c_change(colour)
{
document.getElementById("c_bar").style.background = 'c_change/' + colour + '_bar.png';
}


However, this gives me an error.

If i replace the property to a hex code, it works, just doesnt seem to for images.

Any idea how i could get this to work changing bg images?

Thanks :)

Protege
23-12-2008, 04:20 PM
style.backgroundImage = "url(/'images/imagename.png')";
CHeck that though.

MrCraig
23-12-2008, 04:24 PM
"url is not defined"

Jackboy
23-12-2008, 04:31 PM
i dnt know js but it cud be

style.backgroundImage = "url('images/imagename.png')";

Possibly?

Protege
23-12-2008, 10:53 PM
no idea why i had that forward slash in it luls

MrCraig
27-12-2008, 03:16 PM
ye me neither LOL :P

Any other suggestions? :)
+ VIP out :(

Decode
27-12-2008, 05:09 PM
function c_change(colour)
{
document.getElementById("c_bar").style.backgroundImage = '/c_change/' + colour + '_bar.png';
}

Jxhn
28-12-2008, 02:38 PM
function c_change(colour)
{
document.getElementById("c_bar").style.backgroundImage = "url(\"c_change/" + colour + "_bar.png\")";
}

MrCraig
28-12-2008, 03:09 PM
John, im officially in love.

Thank you :)
+REP to all who helped (if i can)

Want to hide these adverts? Register an account for free!