473,785 Members | 3,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Focus cursor to textbox

18 New Member
im using javascript for loading the login screen.

in form load i focus the cursor in username textbox.
Mar 24 '08 #1
7 2785
pshm
20 New Member
try with this
document.formna me.controlname. focus();
or
document.getEle mentById('id of the control').focus ();

ex:
[HTML]<script type="text/javascript">
<!--
window.onload=f unction(){
document.getEle mentById('txtUI D').focus();
}
-->
</script>
<body>
<input type="text" id="txtUID" />
</body>[/HTML]
Mar 24 '08 #2
hsriat
1,654 Recognized Expert Top Contributor
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="documen t.forms[0].username.focus ()">[/html]
Replace username with the name of the username textbox.
Mar 24 '08 #3
deepikashalini
18 New Member
Add a script to the onload event of the body.
Like this[html]<body onload="documen t.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 Recognized Expert Top Contributor
Add statement document.getEle mentById("usern ame").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 Recognized Expert Moderator MVP
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
deepikashalini
18 New Member
Add statement document.getEle mentById("usern ame").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.getEle mentByid("usern ame").focus(); then login screen doesn't show.

html:


1.<div id="cart">
2.<script type="text/javascript">doc ument.write(dis playLogin());</script>
3.</div>

javascript:

function displayLogin()
{
//html code here

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

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

Similar topics

3
1189
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
8731
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 search records in a database. On several forms in my application I show (modal) this form to search records. Everytime I show the form I want the focus to be on the textbox on the usercontrol. This works the first time I display the form. But...
3
12734
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. Below are two snippets from the page source as pulled directly out of Firefox after viewing the page: I. HTML CODE BLOCK FOR TEXTBOX
3
6772
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 event for each tab, I put a textbox1.focus but the textbox doesn't contain the cursor. How can I do this?
3
6236
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 possible .
33
3982
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 usereg.jsp. Now i need to focus the cursor in first textbox of usereg.jsp. Since there is no body tag in this jsp i cannot call onload="document.formname.textboxname.focus()". But i need the focus in textbox when i call this page in main.jsp.
3
1462
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
18359
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 PalletNo,TotalPallets,ItemNo,LONo,PONo,BatchNo,LotNo,Cartons,PcsPerCarton etc. Now when person scan a barcode from paper it will automatically enter Number(Like 24914) in first PalletNo TextBox. In the AfterUpdate event of PalletNo TextBox I put some code so it will search the values of...
2
4390
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 mobile. any work around this problem. i hope i have made my statement clear i saw other thread too but that seems to be dead Thanks
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.