954,591 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

getElementById is not a function

I'm testing something on an old version of netscape, specifically 4.7. Everythings fine except for my javscript function doesn't work because it says getElementById is not a function:

document.getElementById('ncp').src = "ncp" + pictureNum + ".jpg";


I've got many more of these type lines but it works fine in IE and FF. Is there something I can do to make this compatible with netscape browsers?

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

You'll have to navigate the hierarchy. For example, use the document.images collection.

I made the decision long ago that I simply wasn't going to worry myself, or add huge development overhead, to supporting old browers, particularly for corporate development projects and/or sites. Use a strict DOCTYPE, code to that standard, cut down on the fancy stuff, and use server-side code as much as possible.

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

I just decided to scrap the idea. I couldn't get anything to work without changing a bunch of code. I think to really get it to work you have to use layers with netscape, but it's just not worth it.

Thanks for the help!

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

Netscape 6+ supports getElementById.
If you require support for Netscape 4 (about 1 visitor in 500 or less now) then you need to use document.layers instead just for those visitors and use getElementById for everyone else.

felgall
Junior Poster in Training
50 posts since Aug 2004
Reputation Points: 13
Solved Threads: 1
 

Yeah, the layers is the only way in netscape.

shephunts
Newbie Poster
5 posts since Sep 2005
Reputation Points: 10
Solved Threads: 0
 

document.getElementById("supplier_no").value = values_array[0];

java script: some times i get error as getElementById is invalid function or returns null. It works perfect in IE but not in Firefox. what is the reason...

agb_bbsr
Newbie Poster
1 post since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You