...

View Full Version : shorten form focus script



buildrebuild
02-16-2007, 06:18 PM
Can antone tell me how to shorten this script? The script is used to highlight which input/textarea box has focus in IE.

sfFocus = function() {
var sfEls = document.getElementsByTagName("INPUT");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onfocus=function() {
this.className+=" sffocus";
}
sfEls[i].onblur=function() {
this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
}
}
var sfEl = document.getElementsByTagName("TEXTAREA");
for (var i=0; i<sfEl.length; i++) {
sfEl[i].onfocus=function() {
this.className+=" sffocus";
}
sfEl[i].onblur=function() {
this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfFocus);

vwphillips
02-16-2007, 07:14 PM
sfFocus = function(){
var sfEls=document.getElementsByTagName('*');
for (var i=0;i<sfEls.length;i++){
if (sfEls[i].tagName=='INPUT'||sfEls[i].tagName=='INPUT'){
sfEls[i].onfocus=function(){ this.className+=' sffocus'; }
sfEls[i].onblur=function(){ this.className=this.className.replace(' sffocus',''); }
}
}
}

buildrebuild
02-17-2007, 05:03 PM
Tried out that script but it didn't work. Also did a few variations on it and it didn't work either.

Tried this to no avail...
var sfEls = document.getElementsByTagName("input") = document.getElementsByTagName("textarea");

Best
CB



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum