473,320 Members | 2,027 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,320 software developers and data experts.

Focus cursor to textbox

im using javascript for loading the login screen.

in form load i focus the cursor in username textbox.
Mar 24 '08 #1
7 2768
pshm
20
try with this
document.formname.controlname.focus();
or
document.getElementById('id of the control').focus();

ex:
[HTML]<script type="text/javascript">
<!--
window.onload=function(){
document.getElementById('txtUID').focus();
}
-->
</script>
<body>
<input type="text" id="txtUID" />
</body>[/HTML]
Mar 24 '08 #2
hsriat
1,654 Expert 1GB
im using javascript for loading the login screen.

in form load i focus the cursor in username textbox.
Add a script to the onload event of the body.
Like this[html]<body onload="document.forms[0].username.focus()">[/html]
Replace username with the name of the username textbox.
Mar 24 '08 #3
Add a script to the onload event of the body.
Like this[html]<body onload="document.forms[0].username.focus()">[/html]
Replace username with the name of the username textbox.

my code is
Expand|Select|Wrap|Line Numbers
  1. function displayLogin()
  2. {
  3.     var log='<form name="frmLogin" action="login" method="post"><table class="listTable" cellpadding="0" cellspacing="0" class="moduletable"><tr>';
  4.     log+='<tr><td><font size="2"> New User </font><a href="javascript:displayRegister()">';
  5.     log +='<font size="3" color="#8B0000" font-weight="bold">&nbsp;Sign Up </font></a></td></tr>';
  6.     frmName="frmLogin";
  7.     login="login";
  8.     log +='<span class="navTitleWhite">LOGIN</span></tr><tr><td>';
  9.     log +='<table class="listTable" width="100%" border="0" cellspacing="0" cellpadding="0" align="center">';
  10.     log +='<tr><td size="10"><b>Email</b>&nbsp;<font id=\"required\">*</font><br><input name="username" type="text" class="inputbox" alt="username" size="17" onkeydown="if(event.keyCode==13) event.keyCode=9;" document.getElementById("username").focus();>';
  11.     log +='<br><b>Password</b>&nbsp;<font id=\"required\">*</font><br><input type="password" name="password" class="inputbox" size="17" alt="password" onkeydown="if(event.keyCode==13) event.keyCode=9;" >';
  12.     log +='<input type="hidden" name="option" value="login">';
  13.     log +='<br><br><center><input type="button" name="Submit" class="button" value="Login" onclick=" return validate(this.form);"></center>';
  14.     log +='<br><input type="checkbox" name="remember" class="inputbox" value="yes" alt="Remember Me" onkeydown="if(event.keyCode==13) event.keyCode=9;"> ';
  15.     log +='Remember me        <br></td>';
  16.     log +='</tr><tr></tr><tr><td><a href="javascript:forgotPassword()">';
  17.     log +='<font color="#8B0000">Forgot your password?</font></a></td></tr></table>';
  18.     log +='</td></tr></table></form>';
  19.     return log;
  20. }
i call this javascript function in my aspx page
Mar 24 '08 #4
hsriat
1,654 Expert 1GB
Add statement document.getElementById("username").focus(); just before return log.

alt is not a valid attribute for input tag.
Use id instead of alt in username field.

There are lots of other mistakes too in your code.
Mar 24 '08 #5
acoder
16,027 Expert Mod 8TB
deepikashalini and pshm, please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for everyone to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Mar 24 '08 #6
Add statement document.getElementById("username").focus(); just before return log.

alt is not a valid attribute for input tag.
Use id instead of alt in username field.

There are lots of other mistakes too in your code.


Hi i add the document.getElementByid("username").focus(); then login screen doesn't show.

html:


1.<div id="cart">
2.<script type="text/javascript">document.write(displayLogin());</script>
3.</div>

javascript:

function displayLogin()
{
//html code here

}
Mar 25 '08 #7
hsriat
1,654 Expert 1GB
Ok, call it just after that part of the code where you have called displayLogin()
[html]<script type="text/javascript">
document.write(displayLogin());
document.getElementById('username').focus();
</script>[/html]
Mar 25 '08 #8

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

Similar topics

3
by: A.M | last post by:
Hi, Can I configure a TextBox to have focus and cursor on it when page gets loaded? Thanks, Alan
5
by: Tosch | last post by:
I have a usercontrol with a label, a textbox, a treeview, a grid and a couple of checkboxes. The usercontrol is hosted on a form together with a cancel and a accept button. This form is used to...
3
by: Joey | last post by:
I have a javascript piece that sets focus to a textbox on one of my webforms. The script works fine for IE: it sets the cursor blinking in the textbox. In Firefox, however, it doesn't work at all....
3
by: Henry Jones | last post by:
VS 2005 On a form I have a tabcontrol with 5 tabs. Each tab has three textboxes on it. When I click on each tab, I would like to have the focus set to the first textbox. On the tabenter...
3
by: muskan | last post by:
hello I want to set the focus in textbox control. I have tried a lot but it is not woking.Tell any property or method for this but without setting the tabindex property. so how it will be...
33
by: me2tech | last post by:
Hi, This is ram. I am developing a page(usereg.jsp) with two textboxes one for username and another for email. Since i am using this page in main.jsp using Ajax, I am removing the body part in...
3
by: nityaprashant | last post by:
how to set focus on textbox inside panel(asp panel) inside ajax update panel plz help me..it's urgent...
4
by: billa856 | last post by:
Hi, My Project is in MS Access 2002. In that I have one form which I am using for data entry. Now in that I have some TextBoxes like...
2
by: zahid313 | last post by:
Hi all i am trying to set focus in textbox. Its a System.Web.UI page. and textbox is System.Web.UI.WebControls so using setfocus works fine in desktop window but setfocus doesnt work in windows...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.