Results 1 to 9 of 9
  1. #1
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default [JS] bg change help pls

    Hey,

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

    HTML Code:
    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
    Coming and going...
    Highers are getting the better of me

  2. #2
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    style.backgroundImage = "url(/'images/imagename.png')";
    CHeck that though.
    Hi, names James. I am a web developer.

  3. #3
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    "url is not defined"
    Coming and going...
    Highers are getting the better of me

  4. #4
    Join Date
    Sep 2005
    Location
    East London
    Posts
    3,028
    Tokens
    0

    Latest Awards:

    Default

    i dnt know js but it cud be

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

    Possibly?

  5. #5
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    no idea why i had that forward slash in it luls
    Hi, names James. I am a web developer.

  6. #6
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    ye me neither LOL

    Any other suggestions?
    + VIP out
    Coming and going...
    Highers are getting the better of me

  7. #7
    Join Date
    Dec 2006
    Posts
    3,970
    Tokens
    0

    Latest Awards:

    Default

    HTML Code:
    function c_change(colour)
    {
        document.getElementById("c_bar").style.backgroundImage = '/c_change/' + colour + '_bar.png';
    }
    Lets set the stage on fire, and hollywood will be jealous.

  8. #8
    Join Date
    Jun 2008
    Location
    Manchester
    Posts
    766
    Tokens
    0

    Default

    Code:
    function c_change(colour)
    {
        document.getElementById("c_bar").style.backgroundImage = "url(\"c_change/" + colour + "_bar.png\")";
    }

  9. #9
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    John, im officially in love.

    Thank you
    +REP to all who helped (if i can)
    Coming and going...
    Highers are getting the better of me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •