473,386 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Cursor on the Username text box

I have a Login Page with a Username text box and another one for
Password. How can I have the cursor in the Username text box once the
page loads.
Do I need to have a client side script??

Please help

Thanks in advance
Renuka
Nov 18 '05 #1
6 1331
Yes - just use a client side script to setFocus() on that control.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Renuka" <re**************@hotmail.com> wrote in message
news:52*************************@posting.google.co m...
I have a Login Page with a Username text box and another one for
Password. How can I have the cursor in the Username text box once the
page loads.
Do I need to have a client side script??

Please help

Thanks in advance
Renuka

Nov 18 '05 #2

How can I use it in ASP.net I tried the following javascript in the head
of Login.aspx

<script language="Javascript">
function setFocus()
{
document.forms.txtLogin.focus();
}
</script>

where txtLogin is the id of the asp:Label. And then calling this
function in the body.

<body onLoad="setFocus()">

Please help it gives an error on the line
document.forms.txtLogin.focus();
The error is : Microsoft JScript runtime error:
'document.forms.txtLogin' is null or not an object

Thanks for your help.
Renuka

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3
ASP.NET reserves the right to mangle IDs wherever it deems it appropriate.
When you open your page, go to view -> source and look for the <input
type="text" /> that is rendered for the control you are trying to set the
focus on, and then use this value. Alternately, an even better solution is
to have your server response.write the UniqueID of this control, which
guarantees that future name mangling schemes of the web controls will not
break your script.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Renuka Srivastava" <re**************@hotmail.com> wrote in message
news:uB**************@TK2MSFTNGP12.phx.gbl...

How can I use it in ASP.net I tried the following javascript in the head
of Login.aspx

<script language="Javascript">
function setFocus()
{
document.forms.txtLogin.focus();
}
</script>

where txtLogin is the id of the asp:Label. And then calling this
function in the body.

<body onLoad="setFocus()">

Please help it gives an error on the line
document.forms.txtLogin.focus();
The error is : Microsoft JScript runtime error:
'document.forms.txtLogin' is null or not an object

Thanks for your help.
Renuka

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #4
document.forms is a collection. Assuming your form is called "Form1" the
following should work:

document.forms["Form1"].elements["txtLogin"].focus();

Regards,

Mun

"Renuka Srivastava" <re**************@hotmail.com> wrote in message
news:uB**************@TK2MSFTNGP12.phx.gbl...

How can I use it in ASP.net I tried the following javascript in the head
of Login.aspx

<script language="Javascript">
function setFocus()
{
document.forms.txtLogin.focus();
}
</script>

where txtLogin is the id of the asp:Label. And then calling this
function in the body.

<body onLoad="setFocus()">

Please help it gives an error on the line
document.forms.txtLogin.focus();
The error is : Microsoft JScript runtime error:
'document.forms.txtLogin' is null or not an object

Thanks for your help.
Renuka

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #5
use something like

document.forms[0].<%=txtlogin.clientid%>.focus();
"Chris Jackson" <chrisjATmvpsDOTorgNOSPAM> wrote in message
news:uV**************@TK2MSFTNGP10.phx.gbl...
Yes - just use a client side script to setFocus() on that control.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Renuka" <re**************@hotmail.com> wrote in message
news:52*************************@posting.google.co m...
I have a Login Page with a Username text box and another one for
Password. How can I have the cursor in the Username text box once the
page loads.
Do I need to have a client side script??

Please help

Thanks in advance
Renuka


Nov 18 '05 #6


Thanks!
It worked
Renuka

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: DarthMacgyver | last post by:
Hello, I recently wrote a survey application. Each question is very similar. The first questions gives me a problem when there are multiple people taking the survey (The Database connection...
10
by: teddysnips | last post by:
Application is a Work Tracking/Timesheet database. The increments of work are stored in the TimesheetItem table. This contains, inter alia, the Work Code, the Start and the Duration that the...
3
by: PeP | last post by:
Good morning, I have a form containing a text-area, I'd like to know if it exists a function that, when I activate an event, returns the position of the cursor in the text-area. For example, I...
1
by: David R. | last post by:
Using <asp:Login ID="Login1" runat="server"> Is it possible to set the initial cursor focus on the Username text field when the page initially loads?
4
by: Billy | last post by:
Hi all, I'm building a text file from a database table using the ASP Write Method and would like to position the cursor in a specific column position before writing the fields. As I loop through...
1
by: mrdude | last post by:
i am working on a web analysis project. i am having difficulty with counting hits and visits (a group of hits without a 30 minute break between hits). i decided to build a cursor in order to...
5
by: Florian Lindner | last post by:
Hello, I have a string: INSERT INTO mailboxes (`name`, `login`, `home`, `maildir`, `uid`, `gid`, `password`) VALUES (%s, %s, %s, %s, %i, %i, %s) that is passed to a MySQL cursor from MySQLdb:...
0
by: nagarjunt | last post by:
Hi, This is nag. I have a problem with infragistics7.1 UltraTextEditor control. I am using C# code in windows form. I have UltraTextEditor control(With multi line enabled) in my Windows...
5
by: michels287 | last post by:
Right now I have a touchscreen with a virual keyboard. I would like to create arrow keys. If the user messed up the inputted text, he can move the blinking cursor left one space at a time between...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.