buildrebuild
02-16-2007, 05: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);
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);