By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,414 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,414 IT Pros & Developers. It's quick & easy.

Placing the cursor in a textbox

P: n/a
How is it possible to designate a textbox so that when the .aspx page is
displayed the cursor is already there so the user can just start typing
instead of having to click in the textbox with the mouse first?
thanks,
T
Nov 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
javascript: document.forms[0].textboxName.focus();

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

"Tina" <ti**********@removespamexcite.com> wrote in message
news:eK**************@TK2MSFTNGP14.phx.gbl...
How is it possible to designate a textbox so that when the .aspx page is
displayed the cursor is already there so the user can just start typing
instead of having to click in the textbox with the mouse first?
thanks,
T

Nov 19 '05 #2

P: n/a
you can use Javascript to do it. Put this in your html code:

<script language=javascript>
document.Form1.myTextBox.focus();
</script>

where Form1 is the name of your form, and myTextBox is the name of your
textbox.

you can also use .select instead of .focus if you want to highlight any
existing text in the box.

"Tina" <ti**********@removespamexcite.com> wrote in message
news:eK**************@TK2MSFTNGP14.phx.gbl...
How is it possible to designate a textbox so that when the .aspx page is
displayed the cursor is already there so the user can just start typing
instead of having to click in the textbox with the mouse first?
thanks,
T

Nov 19 '05 #3

P: n/a
it doesn't work. a snippet is pasted below. What did I do wrong?
thanks,
T
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<script language="javascript">
document.Form1.tbEmail.focus();
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:textbox id="tbEmail" style="Z-INDEX: 100; LEFT: 208px; POSITION:
absolute; TOP: 120px" accessKey="u"
tabIndex="1" runat="server"></asp:textbox><asp:label id="Label1"
style="Z-INDEX: 101; LEFT: 128px; POSITION: absolute; TOP: 120px"
runat="server"> <u>U</u>sername: </asp:label><asp:textbox id="tbPassword"
style="Z-INDEX: 102; LEFT: 208px; POSITION: absolute; TOP: 184px"
accessKey="p" runat="server" TextMode="Password"
Width="152px"></asp:textbox><asp:button id="btnLogin" style="Z-INDEX: 104;
LEFT: 248px; POSITION: absolute; TOP: 248px"

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Oy**************@tk2msftngp13.phx.gbl...
javascript: document.forms[0].textboxName.focus();

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
What You Seek Is What You Get.

"Tina" <ti**********@removespamexcite.com> wrote in message
news:eK**************@TK2MSFTNGP14.phx.gbl...
How is it possible to designate a textbox so that when the .aspx page is
displayed the cursor is already there so the user can just start typing
instead of having to click in the textbox with the mouse first?
thanks,
T


Nov 19 '05 #4

P: n/a
it doesn't work. a snippet is pasted below. What did I do wrong?
thanks,
T
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<script language="javascript">
document.Form1.tbEmail.focus();
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:textbox id="tbEmail" style="Z-INDEX: 100; LEFT: 208px; POSITION:
absolute; TOP: 120px" accessKey="u"
tabIndex="1" runat="server"></asp:textbox><asp:label id="Label1"
style="Z-INDEX: 101; LEFT: 128px; POSITION: absolute; TOP: 120px"
runat="server"> <u>U</u>sername: </asp:label><asp:textbox id="tbPassword"
style="Z-INDEX: 102; LEFT: 208px; POSITION: absolute; TOP: 184px"
accessKey="p" runat="server" TextMode="Password"
Width="152px"></asp:textbox><asp:button id="btnLogin" style="Z-INDEX: 104;
LEFT: 248px; POSITION: absolute; TOP: 248px"

"Rob T" <RT*********@DONTwalchemSPAM.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
you can use Javascript to do it. Put this in your html code:

<script language=javascript>
document.Form1.myTextBox.focus();
</script>

where Form1 is the name of your form, and myTextBox is the name of your
textbox.

you can also use .select instead of .focus if you want to highlight any
existing text in the box.

"Tina" <ti**********@removespamexcite.com> wrote in message
news:eK**************@TK2MSFTNGP14.phx.gbl...
How is it possible to designate a textbox so that when the .aspx page is
displayed the cursor is already there so the user can just start typing
instead of having to click in the textbox with the mouse first?
thanks,
T


Nov 19 '05 #5

P: n/a
Hello Tina,

I have better luck with:

var ctl = document.getElementById('tbEmail');
if (ctl != null) ctl.focus();

--
Matt Berther
http://www.mattberther.com
it doesn't work. a snippet is pasted below. What did I do wrong?
thanks,
T
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<script language="javascript">
document.Form1.tbEmail.focus();
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:textbox id="tbEmail" style="Z-INDEX: 100; LEFT: 208px;
POSITION:
absolute; TOP: 120px" accessKey="u"
tabIndex="1" runat="server"></asp:textbox><asp:label id="Label1"
style="Z-INDEX: 101; LEFT: 128px; POSITION: absolute; TOP: 120px"
runat="server"> <u>U</u>sername: </asp:label><asp:textbox
id="tbPassword"
style="Z-INDEX: 102; LEFT: 208px; POSITION: absolute; TOP: 184px"
accessKey="p" runat="server" TextMode="Password"
Width="152px"></asp:textbox><asp:button id="btnLogin" style="Z-INDEX:
104;
LEFT: 248px; POSITION: absolute; TOP: 248px"

"Rob T" <RT*********@DONTwalchemSPAM.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
you can use Javascript to do it. Put this in your html code:

<script language=javascript>
document.Form1.myTextBox.focus();
</script>
where Form1 is the name of your form, and myTextBox is the name of
your textbox.

you can also use .select instead of .focus if you want to highlight
any existing text in the box.

"Tina" <ti**********@removespamexcite.com> wrote in message
news:eK**************@TK2MSFTNGP14.phx.gbl...
How is it possible to designate a textbox so that when the .aspx
page is
displayed the cursor is already there so the user can just start
typing
instead of having to click in the textbox with the mouse first?
thanks,
T


Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.