Tuesday, July 9, 2019

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>

No comments:

Post a Comment

Lab 09: Publish and subscribe to Event Grid events

  Microsoft Azure user interface Given the dynamic nature of Microsoft cloud tools, you might experience Azure UI changes that occur after t...