JavaScript DHTML/Document/Focus
Focus blur
<source lang="html4strict">
<html> <body> <script language="JavaScript"> function function1(){
document.getElementById("myButton").blur(); document.getElementById("myButton").innerText = "This button lost its focus"; alert("The button lost its focus");
} </script> <input id="myButton"
type="button" onclick="function1();" value="Tab to put in focus." onFocus="this.innerText="In focus. Click me to lose focus"">
</body> </html>
</source>
Has Focus ?
<source lang="html4strict">
<html> <body> <button onclick="alert(document.hasFocus());">document.hasFocus()</button> </body> </html>
</source>
Set focus to an element
<source lang="html4strict">
<html> <body> <script language="JavaScript">
function function1() { document.all.myElement.focus(); } function function2() { alert("onFocus event has been fired"); }
</script> <input id="myElement" type="text" value="" onfocus="function2();"> <input type="button"
value="Give focus to the text input element and fire the event" onclick="function1();">
</body> </html>
</source>