title: Keep iOS keyboard open while keyup function runs
body: <p>This question is about iOS web dev.</p>
  
  <p>I have a function which is fired by a keyup listener in a "Search" input field.
  It works perfectly on a Desktops, Laptops, Samsung Galaxy phones and the Sony Xperia but not in iPhone or iPad. Whenever the function runs, the soft keyboard closes. One potential fix I thought of was to re <code>focus</code> on the input <code>id='newsearch'</code> as the last line of the function, but that didn't seem to do anything.</p>
  
  <p>Does anyone know how to keep the keyboard open while the function is running in ios?</p>
  
  <p>See 3 code snippets below:</p>
  
  <p><strong>The lines that trigger the function:</strong></p>
  
  <pre><code>&lt;tr&gt;&lt;td colspan='3'&gt;Search &lt;input type='text' autofocus id='newsearch'&gt;&lt;/input&gt;&lt;/td&gt;
  
      &lt;h2&gt;Search Results&lt;/h2&gt;
      &lt;div id="newsearch-data"&gt; &lt;/div&gt;
  
  &lt;script src="http://code.jquery.com/jquery-1.8.0.min.js"&gt; &lt;/script&gt;
  &lt;script src="addplayer.js"&gt; &lt;/script&gt;
  </code></pre>
  
  <p><strong>The function itself:</strong>   addplayer.js</p>
  
  <pre><code>$('input#newsearch').on('keyup', function(){
      var newsearch = $('input#newsearch').val();
      if ($.trim(newsearch)!= "") {
          $.post('newsearch.php', {newsearch: newsearch}, function(data) {
              $('div#newsearch-data').html(data);
          });
      }
  });
              document.getElementById("newsearch").focus();
  </code></pre>
  
  <p><strong>The php file the function refers to:</strong>  newsearch.php</p>
  
  <pre><code>if (isset($_POST['newsearch']) &amp;&amp; $_POST['newsearch'] != NULL){
      require 'dbconnect.php';
  
      $term = $_POST['newsearch'];
      $terms = "%" . $term . "%";
  
      $_SESSION['players'] = array();
  
      $query = ("SELECT * FROM players WHERE Username LIKE '$terms' OR Phonenumber LIKE '$terms' OR PlayerID LIKE '$terms'");
      $run_query = mysqli_query($dbcon, $query);
  
          echo "&lt;table border='1px'&gt;&lt;tr&gt;&lt;th&gt;Player ID&lt;/th&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Action&lt;/th&gt;&lt;/tr&gt;";
  
              while ($dbsearch = mysqli_fetch_assoc($run_query))
               {
                  $dbu = $dbsearch['Username'];
                  $id = $dbsearch['PlayerID'];
                  $func = "add(" . $id . ", Brad Henry )";
               array_push ($_SESSION['players'],$dbsearch['PlayerID']);
               echo "&lt;tr&gt;&lt;td&gt;".$id ."&lt;/td&gt;&lt;td&gt;".$dbu."&lt;/td&gt;&lt;td&gt;&lt;input type=\"submit\" id=\"PlayerAdded".$id."\" autofocus value=\"Add\" onclick=\"add('".$id."','".$dbu."');\"&gt;&lt;/input&gt;&lt;/td&gt;&lt;/tr&gt;";
               }
  </code></pre>