Sunday, February 5, 2012

Prototype - Select First Form Field

It is a common use case to enter a page with the first form field selected for the user.  I've historically implemented very customized JS to accomplish this but with Prototype this is almost too easy.

Event.observe(window, 'load', function() {
     var field = $$('.focus').first();
     if (field) field.focus();
});

No comments: