471,598 Members | 1,378 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Focus on a text field when the page is loaded

258 100+
Hi everyone
I have a chat form and I need my textfield to be the current one when the page is loaded.

Expand|Select|Wrap|Line Numbers
  1.   <form action="" method="post">
  2.      <input type="text" name="text1">
  3.      <input type="text" name="text2">
  4.      <input type="text" name="text3">
  5.      <input type="text" name="text4">
  6.   </form>
  7.  
For example I need to focus on ( text2 ) when the page is loaded... and i dont what the user to click on it to activate it every time he/she wants to type a message
Sep 25 '07 #1
4 1977
drhowarddrfine
7,435 Expert 4TB
HTML cannot do this. You need to ask on the javascript board.
Sep 25 '07 #2
First of all, change the name tag to id or just add it aswell, so javascript can access it. It should look like this then:

<form action="" method="post">

<input type="text" name="text1" id="text1">
<input type="text" name="text2" id="text2">
<input type="text" name="text3" id="text3">
<input type="text" name="text4" id="text4">

</form>

then in the body tag add: onload="document.getElementById('text2').focus()"

Hope this helps
Sep 25 '07 #3
bnashenas1984
258 100+
Thanks for your help
It worked!
Actualy I'v used the same thing in visual basic and was wondering if theres such a thing in HTML.
My chatroom is working perfect now ( Thanks to you and other users who helped me)
Sep 25 '07 #4
Death Slaught
1,137 1GB
First of all, change the name tag to id or just add it aswell, so javascript can access it. It should look like this then:

[HTML]<form action="" method="post">

<input type="text" name="text1" id="text1">
<input type="text" name="text2" id="text2">
<input type="text" name="text3" id="text3">
<input type="text" name="text4" id="text4">

</form>[/HTML]
then in the body tag add: onload="document.getElementById('text2').focus()"

Hope this helps
Sup FullH3ktik, please use proper code tags when posting code. ( please see posting guidelines )


Thanks, Death
Sep 25 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by 'bonehead | last post: by
11 posts views Thread by JCO | last post: by
6 posts views Thread by Csaba | last post: by
2 posts views Thread by Rey | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

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.