Solved

referencing controls - getElementById

Posted on 2013-02-01
6
140 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 500 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

728 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