Search code examples
androidhtmlaccessibilitytalkback

Onclick event for input field doesn't work while accessibility screen reader is running


Onclick event for input field doesn't work while accessibility screen reader is running.

I use this HTML example for many years. But since Android 8, it doesn't work. Until Android 8, the onclick event was triggered by a double-tap action while the screen reader is running.

<input type="text" name="pwd1" id="pwd1" onclick="alert('test');" />

I want it to work as before Android 8. I want the onclick event for a div to act as a double tap. But since Android 8, it doesn't work.


Solution

  • Using onclick on an input text field is anyway a bad practice. You should probably use onfocus instead.

    Reasons why you shouldn't use onclick include:

    • It isn't triggered when the field is focused using the keyboard or anything other than the mouse
    • It may be triggered even if the field is already in focus, for example when selecting or moving the insertion point

    You probably want to do something when the field gets the focus, not when the field is clicked; in that case, use onfocus.