473,387 Members | 3,801 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,387 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 2154
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

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

Similar topics

5
by: 'bonehead | last post by:
Greetings, I'm still something of a newbie to html/php/mysql. I have a php/html form with several fields of type "input". If the user enters improper data in a particular field and clicks the...
5
by: Mike Hnatt | last post by:
I'd like the focus to be on "mycontrol" when the page is first loaded. I'm getting an undefined error and am assuming that I can't do this in the body ONLOAD event because the control is not yet...
11
by: JCO | last post by:
I have a text box, on my form that I cant get the focus on. I'm using it as shown: <head> <body onload=document.getPassword.txtPasswordName.focus()> </head> Where getPassword is the form &...
6
by: Csaba | last post by:
I'd like to have the cursor in the login form's username input text field when users load the login page. It works fine with the following implementation: <body...
3
by: Dai Ba Wong | last post by:
Hi: Currently I am having a problem with my webpage. My page consist of two frames, one consist of input text field and the other contains link for different pop-up windows. The problem...
4
by: PK9 | last post by:
I have a button at the top of my page that I have an onClick event handler for which makes some new controls (at the bottom of my page) visible. When the user clicks the button I make the new...
4
by: bienwell | last post by:
Hi, I have a problem and really need your help. In my web page ASPX, I have some text fields to accept data from users. I did form validation like this : <td class="dataTD" style="HEIGHT:...
2
by: Rey | last post by:
Howdy all. Using visual web developer (VB) on xp pro box. My problem with with a web form that on accessing the calendar control causes a postback that moves the cursor back to the txtFirstName...
9
by: bnashenas1984 | last post by:
Hi everyone I have a chat form and I need my textfield to be the active one when the page is loaded. <form action="" method="post"> <input type="text" name="text1"> <input type="text"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.