Solved

referencing controls - getElementById

Posted on 2013-02-01
6
137 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

815 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