Focus event in JavaScript

Onfoucs event will be fired when control get the focus.

Example:

Place the curosr in the below texboxes.

Code Sample:

<html> <head> <title>Onfocus event example in JavaScript</title> <script language="Javascript"> var cnt = 0; var arybg = new Array("Red", "Green", "Blue", "Yellow", "Black", "Brown"); function onfocusevt(evt, t) { if (cnt == arybg.length) cnt = 0; t.style.backgroundColor = arybg[cnt]; cnt++; } </script> </head> <body> <table align="center"> <tr> <td> Place the curosr in the below texboxes. </td> </tr> <tr> <td> <input type="text" id="Text1" onfocus="onfocusevt(event,this);" /> </td> </tr> <tr> <td> <input type="text" id="Text2" onfocus="onfocusevt(event,this);" /> </td> </tr> <tr> <td> <input type="text" id="Text3" onfocus="onfocusevt(event,this);" /> </td> </tr> <tr> <td> <input type="text" id="Text4" onfocus="onfocusevt(event,this);" /> </td> </tr> <tr> <td> <input type="text" id="Text5" onfocus="onfocusevt(event,this);" /> </td> </tr> </table> </body> </html>