How do I set the focus to the first form field?

Author Topic: How do I set the focus to the first form field?  (Read 747 times)

Offline chinmay.sahooTopic starter

  • Trade Count: (0)
  • Full Member
  • ***
  • Thank You 2
  • Posts: 158
  • Karma: 0
    • Hot Shaper
How do I set the focus to the first form field?
« on: 01-31-2017, 06:07:27 »
You cannot do this with HTML. However, you can include a script after the form that sets the focus to the appropriate field, like this:

<form id="myform" name="myform" action=...> <input type="text" id="myinput" name="myinput" ...> </form>
<script type="text/javascript"> document.myform.myinput.focus();</script>

A similar approach uses <body onload=...> to set the focus, but some browsers seem to process the ONLOAD event before the entire document (i.e., the part with the form) has been loaded.


 

Related Topics

  Subject / Started by Replies Last post
2 Replies
1587 Views
Last post 05-24-2011, 12:18:18
by seogenius
0 Replies
1421 Views
Last post 09-08-2011, 07:13:39
by Zekecamusio
4 Replies
2278 Views
Last post 01-23-2013, 06:38:53
by xavier7
0 Replies
915 Views
Last post 01-11-2014, 10:47:19
by Blogger-Aassif
5 Replies
2148 Views
Last post 10-30-2016, 01:11:00
by NamRay