Using Chrome on Android, I'm trying to both get and set the value of an Input Text box.
I'm using this code to simulate a keypress in my web application, because of this bug in Chrome on Android.
<input type="text" id='dummyForMobileKeyboard' style='position: absolute; top: -100px; left: -100px; width: 1px; height: 1px; opacity: 0;' />
<script>
var dummyBox = document.getElementById('dummyForMobileKeyboard');
dummyBox.onkeyup = () => {
var e = new KeyboardEvent('keydown', {
bubbles: true,
cancelable: true,
keyCode: dummyBox.value.charCodeAt(dummyBox.value.length - 1),
key: dummyBox.value.substring(dummyBox.value.length - 1),
});
document.onkeydown(e);
dummyBox.value = '';
}
</script>
When running this on a Windows computer, it works perfectly as intended, however on Chrome in Android, setting the value of the text box back to ''
simply does nothing.
This means when the backspace key is pressed, it instead enters the character you entered before last, and only erases text when there is no text left in the box.
Is there an alternate way to do this? Google searches suggest you can only use .value and there is no other way to set the value back to nothing.