SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Form focus
Hybrid View
-
Jan 17, 2001, 13:14 #1
- Join Date
- Nov 2000
- Location
- A home in the hills where the grass grows green an
- Posts
- 183
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Not a question, but a tidbit. There was someone askig before about how to start off a form with the cursor in a particular text box. Well, this is how to do it (very simple):
Put this script directly AFTER your form
Code:<script language="JavaScript"> <!-- document.form_name.input_name.focus() //--> </script>
-
Jan 17, 2001, 15:24 #2
- Join Date
- Aug 1999
- Location
- Pittsburgh, PA, USA
- Posts
- 3,910
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
In case you're a JS newbie of sorts, try this:
Code:<html> <head> <title>A Page</title> <script language="JavaScript"> <!-- function changeFocus() { document.form1.email.focus() } //--> </script> </head> <body onLoad="changeFocus();"> <form name="form1" action="somepage.cgi" method="post"> Email Address: <input type="text" name="email"><br> <input type="submit" name="submit" value="Send Email"> </form> </body> </html>
I don't know for sure whether you'll still required to specify the NAME attribute in your FORM tag, but it can't hurt either way.
-
Jan 20, 2001, 14:03 #3
- Join Date
- Apr 2000
- Location
- Melbourne, Australia
- Posts
- 2,571
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Heck, if you want to focus on the first field of the first form on the page, you can use:
document.forms[0].elements[0].focus();Kevin Yank
CTO, sitepoint.com
I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
Baby’s got back—a hard back, that is: The Ultimate CSS Reference
Bookmarks