0

This is going to be hard to describe since I don't work in Javascript that often.

Currently I am trying to creating a login page. Upon opening the page I want the user to be automatically sent to the "Enter your Username" tab, meaning I want the cursor to start blinking on it automatically.
The best example I can think of this is in Gmail where when you open the login page, the "Enter your email" tab starts blinking automatically. I cant get more technical than this. Any helpful response would be appreciated.

image of gmail login page

the_pete
  • 822
  • 7
  • 19
jthedudeoflife
  • 391
  • 1
  • 4
  • 11

3 Answers3

1

Either use the new HTML5 <input autofocus> attribute on the field you want focused first or use Javascript to call .focus() on the input element.

Philip
  • 769
  • 7
  • 20
1

try like this

<input type="text" name="name" id="xax" autofocus />

Demo

If You need to use JavaScript.

<input type="text" id="search" />
<script type="text/javascript">
document.getElementById('search').focus()
</script>

Demo

RaMeSh
  • 3,330
  • 2
  • 19
  • 31
1

use jQuery.. first provide a id to the text box e.g uname and write script as

 $(function(){
$('#uname').focus();

})

hope you will include .min file & write the above code between <script>

lakshman
  • 656
  • 4
  • 18