OnFocus events In Java Script

This event occurs when objects receives the focus. When we start working with an object that object gets focus. Whether we click on that object or type in it the focus remains on that object. We can program this onfocus event when the focus is brought on the object specified with this event.
 
Example:
 
<html>

<head>

<title>events </title>

</head>

<body bgcolor=green text=”white”>

<h3 align=center> In this example we used Javascript with in inverted quotes </h3>

Name :<input type=”text” name=”t1″ onFocus=”alert(‘It Got Focus ‘)”> <br>

Address : <input type=”text” name=”t2″ onFocus=”alert(‘Now focus is on second text box’)”> <br>

</body>

</html>

click here to view result of this program on browser
 
 
Example:
 
<html>

<head>

<title>events </title>

</head>

<body bgcolor=green text=”white”>

<h3 align=center> <u>In this example we used Javascript with in inverted quotes </u></h3>

<h4 align=center> just click in second text box and type some thing </h4>

Name :<input type=”text” name=”t1″> <br>

Address : <input type=”text” name=”t2″ id=”tt2″ onFocus=”document.all.tt2.style.background=’red’;document.all.tt2.style.c olor=’yellow'”> <br>

</body>

</html>

Scroll to Top