jQuery mobile: Set focus on a textbox?

ElSS picture ElSS · May 25, 2013 · Viewed 8.4k times · Source

I'm trying to set focus on a textbox in jQuery mobile. But it is not working. this is my code

        <script type="text/javascript">
            function FocusOnInput()
            {
                document.getElementById("username").focus();
            }
        </script>

and this is my text box.

<input name="username" id="textinput5"  type="text">

Answer

dsgriffin picture dsgriffin · May 25, 2013

You're using document.getElementById("username") when the ID is actually textinput5.

document.getElementById("username").focus(); should be document.getElementById("textinput5").focus();