SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Firefox says: document.getElementById.bgtd is undefined

    Hi all,

    I have an .asp page on which you can change the background picture of a cell by simply selecting the desired color from a dropdown field.

    When running the page in Firefox its Error console tells me the following:

    Error: document.getElementById.bgtd is undefined
    Source File: [localhost...]
    Line: 29


    Here is the code:


    <select name=ADDITIONALINFO1 ID="Select1" onchange="changebg(document.forms[0].ADDITIONALINFO1[document.forms[0].ADDITIONALINFO1.selectedIndex].value)">
    <option value="White"> White
    <option value="Black"> Black
    <option value="Blue"> Blue
    </select>



    And here is the changebg script:


    function changebg(color){
    if (color=="Black")
    document.getElementById("bgtd").background = "img/bg-tshirt5.jpg";
    else if (color=="Blue")
    document.getElementById("bgtd").background = "img/bg-tshirt_bl.jpg";
    else
    document.getElementById("bgtd").background = "img/bg-tshirt2.jpg";

    document.forms[0].bgimg.value = document.getElementById("bgtd").background;
    }


    Here is the table where the image is displayed as bachground:

    <td width="353" background="img/bg-tshirt2.jpg" height="269" id="bgtd">
    <p align="center"><font size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp;
    <img src="<%=imgSrc%>"></font></td>



    Internet Explorer does not complain and does the job without any errors.
    I Could not find out how to make it work also with Firefox.

    Any comments are appreciated.

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,789
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    document.getElementById("bgtd").background

    should be

    document.getElementById("bgtd").style.backgroundImage
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


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
  •