2

How can I focus a text input with JavaScript (no jQuery) and make the blinking Cursor/virtual Keyboard on iOS devices appear?

This does not seem to be default behavior when you just call:

element.focus();

Solutions using...

element.click();
element.focus();

... as suggested in other Posts also do not work.

Thanks!

Edit: Demo:

function focusText(){

  document.getElementById('text').focus();

}

function focusCalled(){

  document.getElementById('text').value = '';
  document.getElementById('text').type = 'password';

}
<input type="text" id="text" value="Password" onfocus="focusCalled();">
<button onclick="focusText();">Click me!</button>
Ood
  • 1,445
  • 4
  • 23
  • 43

1 Answers1

0

I have this problem when clicking my Clear button only in iOS - but only if the value is already clear. The only way I found so far to get the cursor back in code is a hack as follows...

function ClearInput(sInput)
{
    var oInput = document.getElementById(sInput);
    if (oInput.value.length > 0) oInput.value = '';
    else
    {
        oInput.value = ' ';
        setTimeout(function() { ClearInput(sInput); },
            gkiMinTOutTms); // gkiMinTOutTms=20
    }
    oInput.focus();
}