Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-06-18
3
Medium Priority
?
5,261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 43

Accepted Solution

by:
David S. earned 300 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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.
Suggested Courses

636 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