Yahoo Answers is shutting down on 4 May 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Problem with getElementById?

I have been creating a page with Javascript embedded and it works fine. I now want to transfer the script and link it to a js file. However when I do this the getElementById function is returning a null value. How do I get it to return an object from the actual web-page?

An example is

document.getElementById("BUYGS").addEventListener("click",buygoldsingle,false); (Firefox)

document.getElementById("BUYGS").attachEvent("onclick",buygoldsingle); (Internet Explorer)

Update:

I copied over the java and pasted it into a text file renamed with a js.

If it helps the page that works is www.portwood.co.uk/AOtravelinsurance.htm and the page that doesnt work is www.portwood.co.uk/AOtravelinsurancefull.htm - the script is stored at aojava.js

Update 2:

I added a small routine

function popup()

{

alert("Hello World");

alert("Hi There");

temp = document.getElementById("bronzesingle");

alert(temp.value);

}

This works in Firefox but fails in IE8

1 Answer

Relevance
  • ?
    Lv 6
    10 years ago
    Favourite answer

    Mke sure the id of the element on the web-page is exactly the same as the string written into the parameters of the getElementById() function. Otherwise it will return null.

    http://chopapp.com/#d2165e2l

Still have questions? Get answers by asking now.