DelphiFAQ Home Search:

getElementById() works in Internet Explorer but fails in Firefox - why?


comments2 comments. Current rating: 4 stars (1 votes). Leave comments and/ or rate it.


getElementById() works in IE but fails in Firefox - why?


If you have forgotten to add the element's name as an ID, then Internet Explorer will find it, if the name is given.

// Example:

<input type=checkbox name=acl_type>

// the following will work in IE, but not in FireFox
var ctrl = document.getElementById('acl_type');

// define it like this and it will work both in IE and in FireFox
<input type=checkbox name=acl_type id=acl_type>


2007-01-06, 18:41:05
anonymous from United Kingdom  
thanks for this, i had precisely this problem and adding the id attribute fixed it
2008-09-05, 16:03:22
anonymous from United States  
This is actually the way it's supposed to be. This can cause bugs otherwise. See http://cvermule.blo..tbyid.html for more info.



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: