Solved

document.getElementById is 'undefined' for Firefox only - IE works!

Posted on 2008-06-18
3
5,234 Views
Last Modified: 2013-12-07
When I run this code in Firefox this line returns 'undefine'....

document.getElementById("<% =lblUserRole.ClientID %>").innerText

I can view source and see the control.  In IE it works fine.  I've attached the code....

The control should be 'ctl00_ContentPlaceHolder1_lblUserRole' in View/Source.
function OnClientAppointmentResizeStart(sender, eventArgs)  
    {  
        try {
            if (document.getElementById("<% =lblUserRole.ClientID %>").innerText != "999" && document.getElementById("<% =lblUserRole.ClientID %>").innerText != "500")
            {
                // this line returns undefined in FF only!
                alert(document.getElementById("<% =lblUserRole.ClientID %>").innerText);
                alert("You do not have permission to dynamically resize this appointment.");
                eventArgs.set_cancel(true);
            }
            else{
                eventArgs.set_cancel(false);
            }
        } catch(e) {
            alert("OnClientAppointmentResizeStart error:" + e);
        }
        
    }

Open in new window

0
Comment
Question by:RobertNZana
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
David S. earned 75 total points
ID: 21818631
innerText is a proprietary IE property.

firstChild.nodeValue might be the simplest cross-browser alternative.

innerHTML would be another alternative.
0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 21818662
The element you are referencing most likely does not have an id attribute, only the name attribute. In IE the getElementById function defaults to the name attribute if it cannot find an element with the specified id, FF does not, e.g. the following example works in IE but not in FF:

<input type="text" name="txtTest" value="Test" />
<input type="button" value="Get Value" onclick="alert(document.getElementById('txtTest').value);" />

Add the id attribute to the element and it should become cross browser compatible.
0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 21818676
Sorry, my post refers to a different problem, Kravimir's solution is the correct one for your problem.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
#Citrix #Internet Explorer #Enterprise Mode #IE 11 #IE 8
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question