0

For example below, user can press tab button on the keyboard to go to next field. Can I disable this function?

<form action="/action_page.php">
  First name:<br>
  <input type="text" name="firstname">
  <br>
  Last name:<br>
  <input type="text" name="lastname">
  <br><br>
      <select name="gender">
        <option value="M">M</option>
        <option value="F">F</option>
      </select>
  <br><br>
  <input type="submit" value="Submit">
</form> 
A. Miller
  • 55
  • 1
  • 9
  • Possible duplicate of [Disabling tab focus on form elements](http://stackoverflow.com/questions/3682812/disabling-tab-focus-on-form-elements) – Zac Webb Feb 24 '17 at 01:46
  • You can. But you should **not**. – nnnnnn Feb 24 '17 at 01:52
  • 1
    Like @nnnnnn said, you can. But you shouldn't for ADA users. Read more about that here http://www.techrepublic.com/blog/web-designer/creating-an-ada-compliant-website/ – Josh Feb 24 '17 at 01:55

1 Answers1

2

Yes use keydown like this :

document.querySelector('input').addEventListener('keydown', function (e) {
    if (e.which == 9) {
        e.preventDefault();
    }
});
Nadim
  • 280
  • 2
  • 12