The onFocus event handler executes the mentioned JavaScript code or function on the occurrence of a focus event. It is while a window, frame or form element is given the focus. It can be caused through the user clicking on the current frame, window, or form element, using the TAB key to cycle through the several elements on screen, or a call to window .focus method. Be aware that assigning alert box to object's onFocus event handler will result in recurrent alerts as pressing the 'OK'
<SCRIPT LANGUAGE="JAVASCRIPT">
s1 = new String(myform.myText.value)
function changeVal() {
s1 = "I'm feeling focused" document.myform.myText.value = s1.toUpperCase()
}
</SCRIPT>
</HTML>
Figure: Using the onFocus Method
onblur = script
The onBlur event handler executes the denoted JavaScript code or function onto the occurrence of blur event. This is while a window, frame or form element loses focus. It can be caused through the user clicking outside of the current window, frame or form element, using the TAB key to cycle through the several elements on screen, or by a call to the window.blur method.
The onBlur event handler employee the Event objects properties. type - this property denote the type of event. target - this property denote the object to which the event was sent originally.
The following instance illustrate the use of the onBlur event handler to ask the user to check that the details given are correct. Note the first line is HTML code.
<HTML>
<HEAD>
</HEAD>
<BODY>
<FORM NAME = "myform" >
Enter email address <INPUT TYPE="text" VALUE="" NAME="userEmail" onBlur=addCheck( )>
</BODY>
<SCRIPT LANGUAGE="JAVASCRIPT">
function addCheck() {
alert("Please check your email are correct before submitting")
}
</SCRIPT>
</HTML>