Developers Heaven Forum
News: Free Image Hosting:
http://image-host.developers-heaven.net
Share your images free!!!
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
March 12, 2010, 06:47:41 PM


Login with username, password and session length


Pages: [1]   Go Down
  Print  
Author Topic: Javascript Focus Form Field  (Read 43 times)
0 Members and 1 Guest are viewing this topic.
admin
Administrator
Full Member
*****
Offline Offline

Posts: 206


OS:
unknown
Browser:
unknown


View Profile
« on: January 06, 2010, 02:43:45 PM »

Code:
<form name=aaa>
This is GGG: <input type=text name=ggg><br>
This is HHH: <input type=text name=hhh>
</form>

<script type="text/javascript">

function dofo() {
document.aaa.hhh.focus();
}

</script>

<body onLoad=dofo()>

-We create an HTML form and name it aaa because that is easy to type and remember.
-We name our first text field ggg because we have a cat named G
-We name our second text field hhh because we want to.
-We write a little function and call it dofo because we think that is a clever name.
-document.aaa.hhh.focus();
---document - is the object we are manipulating, this page.
---aaa - is our form name.
---hhh - is the element name we want to place the focus on.
---focus() is a built-in Javascript method that places focus, the cursor in this instance.
-We call the function in our HTML body tag using onLoad.

When the page with this script loads, the cursor will be in the second text field, hhh.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Google
   
Powered by MySQL Powered by PHP Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC

Copyright © Developers-Heaven.net 2008. All rights reserved.
Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM