IntelliJ Java IDE
The moose likes HTML, CSS and JavaScript and the fly likes getting the cursor to appear by default Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "getting the cursor to appear by default" Watch "getting the cursor to appear by default" New topic
Author

getting the cursor to appear by default

paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 18130

I have a form that asks for a user name, password and has a submit button. When the form appears, I would like the user name field to be already "selected" so that the user can just type in their user name without having to click on the field first.
Any suggestions?
Nilesh Pereira
Ranch Hand

Joined: Apr 14, 2003
Posts: 53
Create a javascript function called loadPage().
Call document.formname.fieldname.focus() in this function.
Call loadPage() in the onLoad() function of the body tag.
Hope that helps
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 18130

Is it possible to do this without javascript?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
to my knowledge, you are going to need to use js
I know with html you can set tab order, but not focus
<input type="text" onload="self.focus()">
Eric
[ April 16, 2003: Message edited by: Eric Pascarello ]
Nilesh Pereira
Ranch Hand

Joined: Apr 14, 2003
Posts: 53
The form input type text has an attribute tabindex, but that only works in the latest browsers.
 
 
subject: getting the cursor to appear by default
 
Threads others viewed
Submitting a form on pressing Enter key
field value displayed wrongly
how to write the pgm for validating user?
html interpretation
Portlet form data persistence
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture