?
Solved

text field cursor

Posted on 2006-04-12
6
Medium Priority
?
208 Views
Last Modified: 2013-12-12
Hello,
   I have a simple login window in php. When I open that page, I want the cursor be be in the username field by default and not having to click on the username field in order to type into it.
Please suggest.

here is the form I am using:

<form action="LogIn.php" method="post">
<center>

<table>

<td align="left">
<font size=+1>username:
</td>
<td> <input type="text" name="username" size="20" maxlength="40"><br>
</td>

<tr>
<td>
<font size=+1>password:
</td>
<td>
<input type="password" name="password" size="20" maxlength="40"><br>
</td>
</tr>

</table>
<input type="submit" value="login" name="submit">

</center>
</form>      



0
Comment
Question by:kavishshukla
  • 4
6 Comments
 
LVL 17

Accepted Solution

by:
BogoJoker earned 200 total points
ID: 16439008
Hi kavishshukla,

Change: <body>
To: <body onLoad="document.getElementById('user').focus();">

Change:
<td> <input type="text" name="username" size="20" maxlength="40"><br>
To:
<td> <input type="text" name="username" size="20" maxlength="40" id="user"><br>


Joe P
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 16439157
Alternatively you can also use:

<body onload="document.forms[0].elements[0].focus();">

You will have to make sure that there are no hidden input fields before your first form field.

-r-
0
 
LVL 17

Expert Comment

by:BogoJoker
ID: 16439225
Nice, with Roonaans code you won't need to add the id="user" to your username textfield!
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 17

Expert Comment

by:BogoJoker
ID: 16439281
Roonaan, if you use Firefox and you like extensions would you be interested in a Firefox extension for EE?
http://www.experts-exchange.com/Community_Support/Suggestions/Q_21811687.html
Be the first to post something, even if it is negative... ;)

Joe P
0
 
LVL 9

Expert Comment

by:waygood
ID: 16446002
I ususally use this javascript function, so there are no errors if there are no forms on the page:-

function FormSetFocus()
{
  if (document.forms.length > 0)
  {
    var TForm = document.forms[0];

    for (i=0;i<TForm.length;i++)
    {
      if ((TForm.elements[i].type=="text")||
       (TForm.elements[i].type=="textarea")||
       (TForm.elements[i].type.toString().charAt(0)=="s"))
      {
        document.forms[0].elements[i].focus();
        break;
      }
    }
  }
}
0
 
LVL 17

Expert Comment

by:BogoJoker
ID: 16462944
Any of these work for you?
Do you need modifications to any?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question