Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting focus 1

Status
Not open for further replies.

mmaz

Programmer
Nov 22, 2000
347
Hi,

I have several txtfields on my form, and when the user selects a button, I have to find out which txtfields has focus.

How can I do that? Any help would be greatly appreciated.

Thanks in advance,

Marie :)
 
Hmmm, interesting. There is no facility for this directly that I can see, so what you may have to do is this:
<script>
var formFocus;
function catchFocus(form){
for(var j=0;j<form.elements.length;j++){
form.elements[j].onfocus = setVar;
}

}

function setVar(){
formFocus = this.name;
alert(this.name);
}
</script>

<body onLoad=&quot;catchFocus(document.forms[0])&quot;>

So the onLoad resets every form's onfocus to display an alert with the name of the element with focus. We just reset the value of the variable formFocus whenever a form elemen gains focus. :)
b2 - benbiddington@surf4nix.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top