0

I want to know whether it is possible to obtain the label name along the text box. For example, the following code asks the user for their name and "Your name" is the label.

<label>Your name:</label> <input type="text" size="15" name="name" />

I want to know if I can obtain the label name "Your Name" using javascript.

Magnus Hoff
  • 21,529
  • 9
  • 63
  • 82
user782400
  • 1,617
  • 7
  • 30
  • 51

2 Answers2

1

The answer on the first approach is clever:

Find html label associated with a given input

Otherwise use a toolkit and lots of clumsy DOM traversal.

Community
  • 1
  • 1
ʍǝɥʇɐɯ
  • 4,012
  • 7
  • 32
  • 53
  • what if its not a label; since not all websites have label but its something like YOUR NAME How do I obtain "YOUR NAME" from this ? – user782400 Jul 01 '11 at 20:33
0

Javascript Method

document.getElementById('<%=Label.ClientID%>').value

JQuery Method

$('#<%= Label.ClientID %>').val()
Community
  • 1
  • 1
Pankaj Agarwal
  • 11,191
  • 12
  • 43
  • 59