472,960 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,960 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 2145
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.