Need help in javascript
I need to check the focus of a textbox ,if the textbox has the focus then i need to check the content of the textbox,on pressing the enter key if the content of the textbox is null,display an alert .
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Ady50 reputationPosted Jan 4, 2010, 10:20 AM EST
Santhosh NRank #4,788 · 325 reputationPosted Jan 4, 2010, 8:06 PM EST
var txtFocus = null;
window.onload = function() {
var inputs = document.getElementsByTagName('INPUT');
for(var i = 0; i < inputs.length; i++) {
var elem = inputs[i];
if(elem.type == 'text') {
elem.onfocus = function() {
txtFocus = this;
}
elem.onblur = function() {
txtFocus = null;
}
}
}
}
Now you can check the variable "txtFocus" whenever you need to see what textbox has focus, just like this...