Jumping to the First Field with Autofocus

Must Read

Cyber Monday is Like Black Friday, But in the Warm

Have you ever heard of Cyber Monday? Well, if you have shopped online before, you have probably heard this...

Student Loan Companies Are Beneficial For A Student

Student loans are widely available in the loan market of UK. These loans offer sound financial solution to all...

How to Take Advantage of Obama’s Home Refinance and Modification Stimulus Plan

Everyone is aware of the tough financial times facing average Americans. President Barack Obama is no exception and in...

Ways to Beat the High Costs of College

One of the most important things to remember about saving money for college is starting early. Typically, this is...

Nikon D7000, Classic Black-and-White Portraits

There is something timeless about a black-and-white portrait. It eliminates the distraction of color and puts all the emphasis...

Credit Card Debt Consolidation Loans – Demystification

The use of credit cards is among the most wide spread in the world, and most people at least...

you can really speed up data entry if you place the user’s cursor in the first field on the form when they load the page. Many search engines do this using JavaScript, and now HTML5 provides this capability as part of the language.

All you have to do is add the autofocus attribute to any form field, like we already did on the profile page we built in Describing Data with New Input Fields,

<label for=”name”>Name</label>
<input type=”text” name=”name” autofocus id=”name”>

You can have only one autofocus attribute on a page for it to work reliably. If you have more than one, the browser will focus the user’s cursor onto the last autofocused form field.

Falling Back

We can detect the presence of the autofocus attribute with a little bit of JavaScript and then use j Query to focus on the element when the user’s browser doesn’t have autofocus support. This is probably the easiest fallback solution you’ll come across.

function hasAutofocusO {
var element = document.createElementC ‘input’) ;
return ‘autofocus’ in element;
i f(!hasAutofocus()){
$( ‘input[autofocus=true] ‘) .focusO ;

Just include this JavaScript on your page, and you’ll have autofocus support where you need it.

Autofocus makes it a little easier for users to start working with your forms when they load, but you may want to give them a little more information about the type of information you’d like them to provide. Let’s take a look at the placeholder attribute next.

Latest News

Digital Marketing for Beginners

Digital marketing for starter, Let to basic learning about connecting with your audience in the right place...

What are 7 things poor people do that the rich don’t?

1. poor people watch TV in which people read books how many hours you spend in front of the TV and when...

Top 18 best small business ideas for beginners starting

A small business can be frightening and requires plenty of careful planning there are many small business ideas which can be beneficial...

Summer that makes you happy

We saw were already here I've been thinking about some of the things. I used to do with my husband even though...

4 Point to helpful tips specifically for caregivers

What you need to take a vacation. I know it sounds impossible creative and try to make it work for you almost...

More Articles Like This