Thursday, May 3, 2012

Selecting the First Field in a Form

On an HTML page where you want the first field on the page to be selected by default, you can add the following code.  This uses jQuery to find all of the ‘text’ input boxes, and then sets the focus to the first one found.
<script type="text/javascript">
$(function (){
    $("input[type=text]").first().focus();
});
</script>

Or put this at the bottom of your master page if you want it done everywhere.