user967451
user967451

Reputation:

How to prevent the default focus on text fields when using html5's placeholder attribute

If I have a form with the placeholder attribute like so:

<input type="text" name="something" placeholder="username" />
<input type="text" name="somethingelse" placeholder="password" />

When I come to the page with the above form, by default the first text field is focused, i.e. has the cursor in it. This is a problem since I'm using the placeholder text as the labels for the text fields. So if the username field is focused that placeholder text isn't there leaving something confused as to what they should enter in that field.

Upvotes: 2

Views: 1376

Answers (2)

Lachezar
Lachezar

Reputation: 6703

You can always autofocus="autofocus" other input element (if there is submit input for example). Also you can do <body onLoad="document.some-other-element.focus()">

Upvotes: 1

rmorero
rmorero

Reputation: 596

You could force focus to something else through javascript

jQuery(function($){
  $(".someotherelement").focus();
});

Upvotes: 2

Related Questions