DISQUS

Building Browsergames: Making your forms auto-focus

  • Chaos · 1 year ago
    I've written a form autofocus script that does this in a way that handles some of the problems that come up with the topic, and generally automatically figures out what field to focus on. Thought you might want to know. :)
  • sonicatu · 9 months ago
    It`s kinda confusing. You should put an example on the register.php or login.php
  • Luke · 9 months ago
    If you look at the register and login templates, you'll notice that they *
    both* have the code already implemented on them.
    If you are having trouble understanding how document.getElementById() works,
    you may want to learn a little bit more javascript before attempting to add
    it to your projects.
  • MrLollige · 8 months ago
    Ah, wonderful details! Thanks for adding this to the tutorial Luke!
  • Caleb · 3 months ago
    You can also use the tab index property to control where the cursor goes if the person presses tab. It could be annoying if your sign-up and login were on the same page and the cursor jumps from one to the other.

    <input type="text" name="username" tabindex="1">

    1 is highest priority then 2 and so on. 0 will only be cycled through after the others have been.

    Note that this doesn't replace document.getElementByld() ... but it helps for the after ward.