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 1181 times)

Offline chinmay.sahooTopic starter

  • Trade Count: (0)
  • Full Member
  • ***
  • Thank You 2
  • Posts: 158
  • Karma: 0
    • We Helpline
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
1774 Views
Last post 05-24-2011, 12:18:18
by seogenius
0 Replies
1587 Views
Last post 09-08-2011, 07:13:39
by Zekecamusio
5 Replies
2554 Views
Last post 10-30-2016, 01:11:00
by NamRay
0 Replies
603 Views
Last post 03-26-2018, 09:04:59
by ContentDan
5 Replies
5874 Views
Last post 06-22-2018, 01:34:08
by richardmsmith