?
Solved

referencing controls - getElementById

Posted on 2013-02-01
6
Medium Priority
?
141 Views
Last Modified: 2013-02-01
Can anyone please explain the difference between these three statements, and if they are all valid?


document.getElementById("<%= lblProcessingMsg.ClientID %>");

document.getElementById("lblProcessingMsg.ClientID");

document.getElementById(lblProcessingMsg);
0
Comment
Question by:HLRosenberger
[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
  • 3
  • 2
6 Comments
 
LVL 11

Accepted Solution

by:
mcnute earned 2000 total points
ID: 38843916
This is not exclusively javascript:

In the first statement you have a serverside scripting tag, which could be ruby, asp, jsp, etc.
It is valid if the method called within the chevrons returns a string which is represented within the following dom.

The second statement will be valid if there is a dom element in your page which has the id of lblProcessingMsg.ClientID.

The third statement is valid if in your javascript block before the statement a variable has been created with the name lblProcessingMsg and the variable is of type string and the value is represented by a dom element with that value in its ID attribute.

Hope that helped.
mcnute
0
 
LVL 1

Author Comment

by:HLRosenberger
ID: 38843955
What is chevrons ??
0
 
LVL 11

Expert Comment

by:mcnute
ID: 38843966
angular brackets <>. In this case they are wrapping some server side code probably embeded ruby which is used in ruby on rails.
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 1

Author Comment

by:HLRosenberger
ID: 38843981
OK.  This is ASP, actually.
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 38844244
Thanks
0
 
LVL 82

Expert Comment

by:leakim971
ID: 38844278
http://www.4guysfromrolla.com/articles/031710-1.aspx

the first one is the good syntax to reference the label in a javascript code for :
<asp:Label ID="lblProcessingMsg" runat="server" Text="bla bla" />

Open in new window

the second one is a useless string, or for this one :
<span id="lblProcessingMsg.ClientID">bla bla</span>

Open in new window

the third one :
<asp:Label ID="lblProcessingMsg" runat="server" Text="bla bla" />

Open in new window

With:
function someFunction() {
        var lblProcessingMsg = "<%= lblProcessingMsg.ClientID %>";
        document.getElementById(lblProcessingMsg);
}

Open in new window

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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)
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…
Suggested Courses

777 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