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 .
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Santhosh NPosted Jan 5, 2010, 1:06 AM
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...
AdyPosted Jan 4, 2010, 3:20 PM