SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member scotts777's Avatar
    Join Date
    Apr 2002
    Location
    Victoria
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript question

    Hi there, I am having a problem with a Javascript :

    I am trying to make a select input change a table background using an onSelect event like this :

    <select name="select" size="1" onchange="previewme();">

    function previewme() {

    document.all['borderpic1'].style.backgroundImage = "bed.jpg";
    }

    This script refers to a <td id = "borderpic1"> tag. I am trying to make the select box change the background image for this <td> tag.
    For some reason, this will not work. However, if I change it to read

    document.all['borderpic1'].style.background = "lightgreen";

    THAT works. But I am not trying to change the color, I am trying to change the background image. In my javascript reference book it says style.backgroundImage is a valid object/property in IE5+ and Netscape 6 so I assumed I was doing this properly but still no luck.

    Please help!
    thanks

    Scott

  2. #2
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try:
    Code:
    document.getElementById('borderpic1').style.backgroundImage
    document.all is MSIE proprietory dom and will never work in any other browser than that.

    document.getElementById is the newer, standardised DOM recommended by W3C and is used by all forward thinking browser developers (incl. MSIE5+)
    New Plastic Arts: Visual Communication | DesignateOnline

    Mate went to NY and all he got me was this lousy signature

  3. #3
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bill is right, as usual

    Also note that the css spec requires the url() syntax:

    object.style.backgroundImage = "url(http://myurl.com/)"


Bookmarks

Posting Permissions

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