Critical Developers

Programmers Knowledge Base

First focus on first input field

Focused CSS:-

*:focus { outline: none; } /* Reset Browser's default Focus style */

input[type=text]:focus,textarea:focus,select:focus
{
background:#CEE6FF;
border: 1px solid #51CBEE;
}

JScript:-

<script type="text/javascript">
        var $firstInput = $('#mainDiv').find('input[type=text],textarea,select').filter(':not([type=hidden]):enabled:visible:first');
        $(document).ready(function () {
            $firstInput.focus();
        });
</script>

<script type="text/javascript">
        // if page is in Update Panel or Page isPartialPostedBack
        var $firstInput = $('#mainDiv').find('input[type=text],textarea,select').filter(':not([type=hidden]):enabled:visible:first');
        function pageLoad(sender, args) {
            if (args.get_isPartialLoad()) {
                $firstInput.focus();
            }
        }
</script>
Loading