View Single Post
Old 02-14-2003, 08:55 AM   PM User | #1
beetle
Senior Coder

 
Join Date: Aug 2002
Posts: 3,467
Thanks: 0
Thanked 0 Times in 0 Posts
beetle has a little shameless behaviour in the past
Label properties for form elements

Ok, this is pretty simple, but if you've ever wished that the DOM exposed a label property for any form element that had a label specified for it, well, you'll enjoy this.

!! UPDATED A FEW POSTS DOWN !!
Code:
function addLabelProperties( f )
{
    var labels = f.getElementsByTagName( "label" );
    for ( var i = 0; ( label = labels[i] ); i++ )
        f.elements[label.htmlFor].label = label;
}
Just pass it a reference your form and voila! You now have element.label
__________________
My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
“Minds are like parachutes. They don't work unless they are open”
“Maturity is simply knowing when to not be immature”

Last edited by beetle; 06-18-2003 at 06:59 PM..
beetle is offline   Reply With Quote