Get the current focus html object ID in javascript


Get the current focus html object ID in javascript


var objFocus = document.body;
function getCurrentObjectId(){
var inputs = document.getElementsByTagName('INPUT');
for(var i = 0; i < inputs.length; i++) {
var elem = inputs[i];
if(elem.type == 'text') {
elem.onfocus = function() {
objFocus = this;
}
elem.onblur = function() {
objFocus = null;
}
}
}
//alert(objFocus.getAttribute("id"));
return objFocus.getAttribute("id");
}