What am I doing now?
LABEL tags, IE and Firefox... 
Thursday, February 7, 2008, 07:42 PM - General, Scripts
Posted by Administrator
I have a form validation routine, trying to use good feedback and accessible, I'm working off of the label's for attribute in order to get the error message to tell them the exact field they need to look at. So I setup a collection, getElementsByTagName (using label) and then check the for attribute to see if ti matches the current check - Firefox works flawlessly.

Internet Explorer, however, doesn't.

So, after much search and much hair pulling, I found that IE uses 'htmlfor' although the attribute is actually called 'for' - go figure. However, FF doesn't see 'htmlfor', just 'for'...

I setup an if statement that deals with both:

getLabel:function(fI) {
rV=fI;lL=document.getElementsByTagName("label");for (var i=0;i<lL.length;i++) {
if (lL[ i].getAttribute('htmlfor')==fI ||lL[ i].getAttribute('for')==fI)rV=lL[ i].innerHTML;}return rV;}


(where fI is the name of the field which matches the for attribute)
1 comment ( 38 views )   |  0 trackbacks   |  permalink   |   ( 2.9 / 385 )

<<First <Back | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Next> Last>>