Here I’m explaining how to focus cursor to a text field on page load. You can do this with several methods with a simple javascript code. For this, you have to put a name for your form and your text filed. See the sample form below.
<form name="myForm" method="post" action="">
<label>
<input type="text" name="username" />
</label>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</form>
Now just look on the code. You can do this with a single line code within body onLoad.
<body onLoad="document.myForm.username.focus();">
You can call this code with a function like this:
<script>
function curFocus(){
document.myForm.username.focus();
}
</script>
<body onLoad="curFocus();">
Another method is put the code inside the page after the form. See how is it.
<script type="text/javascript" language="JavaScript">
var focusCtrl = document.forms["myForm"].elements["username"];
if(focusCtrl) {
focusCtrl.focus();
}
</script>





![[del.icio.us]](http://www.bijusubhash.com/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://www.bijusubhash.com/wp-content/plugins/bookmarkify/digg.png)
![[Facebook]](http://www.bijusubhash.com/wp-content/plugins/bookmarkify/facebook.png)
![[Fark]](http://www.bijusubhash.com/wp-content/plugins/bookmarkify/fark.png)
![[Google]](http://www.bijusubhash.com/wp-content/plugins/bookmarkify/google.png)
![[Reddit]](http://www.bijusubhash.com/wp-content/plugins/bookmarkify/reddit.png)
![[StumbleUpon]](http://www.bijusubhash.com/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Technorati]](http://www.bijusubhash.com/wp-content/plugins/bookmarkify/technorati.png)
![[Twitter]](http://www.bijusubhash.com/wp-content/plugins/bookmarkify/twitter.png)
![[Windows Live]](http://www.bijusubhash.com/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://www.bijusubhash.com/wp-content/plugins/bookmarkify/yahoo.png)
![[Email]](http://www.bijusubhash.com/wp-content/plugins/bookmarkify/email.png)



blogbookmark.com January 29, 2009 @ 12:07 pm
How do I have the cursor focus to a text field on page load?…
explaining how to focus cursor to a text field on page load. You can do this with several methods with a simple javascript code…
Blogsvine January 29, 2009 @ 12:11 pm
How do I have the cursor focus to a text field on page load?…
Explaining how to focus cursor to a text field on page load. You can do this with several methods with a simple javascript code…
linksmarker.com January 29, 2009 @ 1:02 pm
bijusubhash.com » Blog Archive » How do I have the cursor focus to a text field on page load?…
Explaining how to focus cursor to a text field on page load. You can do this with several methods with a simple javascript code…
PlugIM.com January 29, 2009 @ 1:08 pm
How do I have the cursor focus to a text field on page load?…
Explaining how to focus cursor to a text field on page load. You can do this with several methods with a simple javascript code…
Eric Jablow January 29, 2009 @ 4:22 pm
1. Assigning to document.unload is poor citizenship. If anything else on your page requires similar handling, you will have to have your onload method do more than set the focus, and a lazy programmer might not even change its name from ‘curFocus’. Instead, use addEvent (IE) or addEventListener (Firefox, etc.)
1.1. Instead of using conditional code to choose between addEvent and addEventListener, after you’ve learned to do that, consider using a JavaScript library such as Prototype or jQuery.
2. Adding raw Javascript to your page is messy. Place it in a separate file, and invoke it with a script src=”…” element.
Ex Back April 9, 2009 @ 6:16 pm
I read your posts for a long time and must tell that your articles are always valuable to readers.
Cursor June 12, 2009 @ 5:53 pm
Metallica-Cursors-Download
Metal Cursor Archives
Cursors Download
http://metallicafanatic.blogcu.com/metallica-cursor-download-cursores_4440105.html
Carroll B. Merriman February 12, 2010 @ 10:59 pm
Increddible useful info. I will be back to read other posts also.
Pahulu April 20, 2010 @ 7:34 pm
thanks a lot (: http://www.hepoyna.net
Debt Relief April 21, 2010 @ 4:27 am
Sorry for my bad english. Thank you so much for your good post. Your post helped me in my college assignment, If you can provide me more details please email me.
Racey April 22, 2010 @ 5:34 pm
good work thanks….
Schwark April 24, 2010 @ 3:49 pm
Your content ammazed me alot. thanks for sharing information. online coupons
Uzelac May 5, 2010 @ 11:06 am
Fantastic post, can I link to this from my blog?
thanks…
Ritzer May 13, 2010 @ 8:14 am
nice news i really enjoyed it
will visit more wow
Shacklett May 14, 2010 @ 6:07 pm
I love this post! I too have created my own list. You can find it at Movie Horror List. Movie Horror List
Dorward May 27, 2010 @ 6:09 am
Hi, you?re making some good bloging there!Keep up the hard work!I?ll folow your blog, you could also follow mine! http://www.bestpokernodepositbonus.blogspot.com mine it?s so no good as yours it just talks about Poker Bonus Without Having to make a Deposit!Congratulations for your blog , visit mine and leave your comment there I would apeciate it!
Steiling September 17, 2010 @ 5:10 pm
Nice post thanks buddy…
Edling September 30, 2010 @ 3:20 pm
This post is very good, congrats my friend, keep up the good work! http://repliesnow.com
Mckenley October 3, 2010 @ 8:30 pm
Thanks for the post. I always wondered about this… now its time for ,e to put it into practice
Hannah October 10, 2010 @ 2:13 pm
Good stuff- I’m subscribing to your feed!
Dygert October 11, 2010 @ 12:13 pm
Wonderful post! I am new to your site, was reading content on Google, I will again to check out future articles. Thank you for sharing! http://harrahs.goldenraincasino.com/
Mcdermitt March 13, 2011 @ 4:06 am
Thanks for publishing, good read, you gonna be performing any kind of follow up with the item?
Mosher July 20, 2011 @ 3:42 pm
Great web! Hogwart
Devito July 29, 2011 @ 5:00 pm
thank you
Trulock January 6, 2012 @ 3:47 am
Great Post. Thanks for the info. Glub