Willy Duitt
10-04-2004, 08:55 PM
I know how to use the DOM to create a label:
var label = document.createElement('label');
label.setAttribute('for','firstName');
label.appendChild(document.createTextNode('New Name'));
But I am trying to retrieve the value of a form elements label textNode value... I need to do this without using an id on the label and was hoping to do this thru the input itself...
Although if I wrap the input within the <label><input></label> I can retrieve the textNode thru parentNode.innerHTML... But I need to do this when the label is in another data cell and thus does not share the same parentNode....
<form>
<table>
<tr><td><label for="firstName">First Name: </label></td></tr>
<tr><td><input type="text" id="firstName" name="firstName"
onclick="alert(this.label.getAttribute('for').value)"></td></tr>
</table>
</form>
I've searched and searched without joy...
Any ideas?
.....Willy
var label = document.createElement('label');
label.setAttribute('for','firstName');
label.appendChild(document.createTextNode('New Name'));
But I am trying to retrieve the value of a form elements label textNode value... I need to do this without using an id on the label and was hoping to do this thru the input itself...
Although if I wrap the input within the <label><input></label> I can retrieve the textNode thru parentNode.innerHTML... But I need to do this when the label is in another data cell and thus does not share the same parentNode....
<form>
<table>
<tr><td><label for="firstName">First Name: </label></td></tr>
<tr><td><input type="text" id="firstName" name="firstName"
onclick="alert(this.label.getAttribute('for').value)"></td></tr>
</table>
</form>
I've searched and searched without joy...
Any ideas?
.....Willy