Array

Jumping to the First Field with Autofocus

Must Read

Corporate Blogging: Why should you start a business blog to promote and market your small business

A business blog is a great way to expose yourself and your small business. There are a variety of...

Step 2: Evaluation

Some of the main risks of cloud computing were described, and Chapter 5 provided tips on vendor selection, but...

Bad Credit Debt Consolidation Loans – Learn the Best Methods of Debt Consolidation

If you have bad credit and are looking to consolidate your credit cards and other debts into one low...
Admin
test

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;
$(function(){
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

Top 10 Provinces of Thailand Not to be missed for Travel

10 SuratthaniThe source of the proverbial Chaiya salted egg. Surat Thani is a province with many attractions,...

Underlight As Accent, For Power and The Main Light for Photography

Underlighting, in which fill or accent light comes from under the topic, is not widely used technique in the traditional Portraits, even though it will have...

How To Fix Overexposure As A Creative Tool, The Complete Guide

As an creative tool, overexposure is sort of underrated. What I’m close to propose could be a deliberate and well thought out technique for...

7D Mark II is Canon’s best DSLR cameras without full-frame sensor.

The expected long-awaited Canon EOS 7D Mark II are shipping in November for $ 1,799 without a lens. With a higher price tag, you...

Low key photography and How to isolate your subject.

Low key photography doesn’t depend on underexposure to make its point; the key to low key is that the majority of tones, even correctly...

More Articles Like This