Solved

referencing controls - getElementById

Posted on 2013-02-01
6
135 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
  • 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

757 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

18 Experts available now in Live!

Get 1:1 Help Now