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).
*************** *************** *************** *************** *********