Solved

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

Posted on 2008-06-18
3
5,225 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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry, my post refers to a different problem, Kravimir's solution is the correct one for your problem.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Several part series to implement Internet Explorer 11 Enterprise Mode
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now