473,779 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Returning "Label" value with srcElement

If I am using srcElement (or "target" for non-IE models) to return
various properties of an object I have clicked on, can I access for
"label for" value in any way? I'm thinking, for example, of an input
text box like this:

<label for="fred">User name:</label>
<input type="text" name="hello" id="hello1" size="10">

Now, once a function has:

var obj=event.srcEl ement || event.target;

.... at the top, I should be able to access obj.name and get "hello"
etc, but how can I access the label value of "fred"? I did try
obj.label but it didn't work...

Steve Wylie
Canterbury
England

Feb 5 '07 #1
4 2041
st*****@hotmail .com wrote:
If I am using srcElement (or "target" for non-IE models) to return
various properties of an object I have clicked on, can I access for
"label for" value in any way? I'm thinking, for example, of an input
text box like this:

<label for="fred">User name:</label>
<input type="text" name="hello" id="hello1" size="10">

Now, once a function has:

var obj=event.srcEl ement || event.target;

... at the top, I should be able to access obj.name and get "hello"
etc, but how can I access the label value of "fred"? I did try
obj.label but it didn't work...

Steve Wylie
Canterbury
England
One of the problems you have right away, is that the <labelelement is
supposed to reference the <inputelement properly, and your example is
not doing so.

This would be a proper setup:

<label for="username"> Username:</label>
<input type="text" name="username" id="username" size="10">

As you can see, the <labelelement†™s FOR attribute has a value that is
now identical to the <inputelement†™s NAME attribute. That way, when
someone clicks on the “Username:” text, their browser knows that they
want to edit or add to the contents of the <inputelement whose NAME
attribute has a value of “username”, and will place the cursor inside
the <inputelement†™s field automatically. By sharing the same attribute
value, the browser knows that the <labelis linked to the <input>.

Another problem that you have, is that the <labelis not a parent of
the <inputelement . As such, you cannot simply reference the parent of
the <inputtag and expect to be able to access the properties of the
<labelelement . As such, you will have to walk up the DOM and walk back
down it to the <labelelement .

Of course, another really easy way of accessing the <labelelement is
to make sure that its FOR attribute is the same as the <inputelement†™s
NAME and ID attributes (the way it is supposed to be). That way, all you
have to to is get the <inputelement†™s ID, and you then have the
<label>’s FOR attribute value to filter for.

Without seeing more of your JS, this is the best example I can provide.

I hope this helps.
...Geshel
--
*************** *************** *************** *************** *********
My return e-mail address is an automatically monitored spam honeypot.
Do not send e-mail there unless you wish to be reported as a spammer.
Please send all e-mail to my first name at my last name dot org, with
a subject-line of “NEWSGROUP REPLY FOR NEO GESHEL” (all uppercase).
*************** *************** *************** *************** *********
Feb 5 '07 #2
st*****@hotmail .com wrote:
<label for="fred">User name:</label>
how can I access the label value of "fred"?
If you have the label element object then you can read out the 'htmlFor'
property
element.htmlFor
see
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-96509813>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 5 '07 #3
Apologies - the script I provided was by way of an example (bad one,
obviously) and is not the actual code I am using. I hammered it out
in a hurry without realising that the Label needs to be the same as
the element or it doesn't make sense! Thanks anyway.

Steve

Feb 6 '07 #4
Thanks - that's what I was looking for!

Steve

Feb 6 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1481
by: Paul | last post by:
I am using Visual Studio.net 2005 (and asp.net 2.0) Let's say that in a Web Project, I have created a (Dataset?) called SomeDataset.xsd. On it I have a TableAdapter called SomeTableTableAdapter and a query called GetSomeInfoQuery. In an aspx page I used an ObjectDataSource, and chose as the business object SomeDataSetTableAdapters.SomeTableTableAdapter, then the method GetSomeInfoQuery. On the aspx side of the page I have a have a...
6
7551
by: Flavio | last post by:
Hi I am havin a problem with urllib2.urlopen. I get this error when I try to pass a unicode to it. raise UnicodeError, "label too long" is this problem avoidable? no browser or programs such as wget seem to have a problem with these strings.
13
2556
by: Karl Groves | last post by:
I'm missing something very obvious, but it is getting late and I've stared at it too long. TIA for responses I am writing a basic function (listed at the bottom of this post) that returns data from a query into an array. The intent is that the following code:
1
4604
by: alien_attack | last post by:
I have the a repeater which is databound to an XmlDatasource. Inside the repeater is a Label as follows: <asp:Label ID="lbl" runat="server" Text='<%# XPath("Asset_Metadata/@Value")%>' /> This gives me a "The server tag is not well formed". It seems to be because of the single quotes in the XPath statement. I've tried changing the single quotes to &apos; which compiles fine,
5
1588
jayam
by: jayam | last post by:
Hai everybody, I want to know the reason why the text box which has the label "Name" appears yellow in color. I want to know is there any special reason behind it. bye jayam
4
3344
RMWChaos
by: RMWChaos | last post by:
Darnit all, I expect the code I steal from others to work! =D Below is some code that I got to initiate multiple javascripts on page load (rather than using the "onload=" attribute). According the blog where it was posted, it seems that it works for everyone who posted replies...not a single "this is not working for me" post. The errors I receive are as follows: IE7: expected ";" and then "conditional compilation is turned off" FF &...
0
687
by: navneet gupta | last post by:
I want to put labels on a specified position.How can i do this.
2
2806
by: Jethro | last post by:
Hi guys, I'm a bit of a newbie, but know VB Classic quite well. The above statement appears in some code I'm hacking, and I have added a column to the DataGrid (in the middle, so those to the right have had their index upped by one). Yet the statement above seems to still return the same value. Is the Index value (9) in the statement : CType(e.Row.Cells(9).FindControl("lblTimeleft"), Label)
3
3695
by: Akino877 | last post by:
Hello, I am trying to user a File Chooser with DIRECTORIES_ONLY set. And I would like to be able to hide the "Files of type" label and the associated combo box. I wonder if there is a way to do this programmatically or by using NetBeans? Thank you for your help. Akino.
0
9632
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10302
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10136
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4036
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.