Cursor on the Username text box

R

Renuka

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
 
R

Renuka Srivastava

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
 
C

Chris Jackson

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.
 
M

Munsifali Rashid

document.forms is a collection. Assuming your form is called "Form1" the
following should work:

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

Regards,

Mun
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top