Set UI Focus on the First Field of a Form

Q

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

✍: FYIcenter

A

You cannot do this with HTML. However, you can include a JavaScript after the form that sets the focus to the appropriate field, like this:

    <input type="text" id="myinput" name="myinput" ...>
</form>

<script type="text/javascript"> document.myform.myinput.focus(); </script>

2007-03-03, 4985👍, 0💬