0

Trying to focus on a textarea after an ajax call back function using javascript. This works fine in chrome and ie, but not on IOS safari. Up until this scenerio, fucus has worked fine on my IOS phone.

Here's the idea I had that's unsuccessful. The textarea appears, but it doesn't focus after appearing (for my IOS phone only).

if (window.XMLHttpRequest) { 
    xmlhttp = new XMLHttpRequest(); 
} else { 
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange=function() { 
    if (this.readyState==4 && this.status==200) {
        document.getElementById('test_project').innerHTML=this.responseText;                     
        document.getElementById('textarea_1').focus();
    }
}   

xmlhttp.open("POST","../ajax/forms.php",true);      
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
xmlhttp.send("phase=test");

Here is the example code from ajax/forms.php

<textarea id='textarea_1' maxlength='23'></textarea>

The recommended link didn't seem to fix my problem, but showed me IOS does have issues with focus. Any other suggestions are appreciated.

Bill Demaria
  • 71
  • 2
  • 10
  • what does "unsuccessful" mean? what *does* happen? what errors are showing in the console? also, practice good code hygiene. use proper indentation and you'll save yourself lots of trouble in the future. – I wrestled a bear once. Sep 03 '19 at 14:10
  • Glad you asked about the console, because it works fine in chrome and IE on my desktop. It's my IOS phone that's not taking the focus. – Bill Demaria Sep 03 '19 at 14:40
  • 1
    Possible duplicate of [Mobile Safari: Javascript focus() method on inputfield only works with click?](https://stackoverflow.com/questions/12204571/mobile-safari-javascript-focus-method-on-inputfield-only-works-with-click) – I wrestled a bear once. Sep 03 '19 at 14:57
  • also: https://raygun.com/blog/debug-javascript-mobile-safari/ – I wrestled a bear once. Sep 03 '19 at 14:58

1 Answers1

0

this works correctly works and no problem. you said it not taking focus on IOS. Try this: https://www.whatismybrowser.com/guides/how-to-enable-javascript/safari-iphone

Pooya Behravesh
  • 131
  • 2
  • 10