by Jeremy
30. April 2009 16:51
jQuery is all the rage these days with website development. It seems that a good amount of demos out there just show its flashiness and ability to provide animations. However, there's a functional side of jQuery that should not be overlooked. Here's a simple example that can be useful on every web page that collects user input.
The usability of web forms (forms allowing data entry, not asp.net web forms) can be enhanced by putting the focus on the first input field in the form. ASP.NET developers often perform this task using server-side code (e.g. txtFirstField.Focus() called in Page_Load). Using jQuery, you can apply the following script to any web page that has input fields. Apply this script once across your site and eliminate the need to put the focus on specific fields on each individual page.
$(document).ready(
function() {
$("input:text:first").focus();
}
)