php - Ajax dynamic datatable -


i trying populate table mysql data base on user id. when use few user id option, works. if use , enter user id, displays table data few second , close out.

<html> <script src="http://code.jquery.com/jquery-1.10.2.js"    type="text/javascript"></script> <head> <script> function showuser(str) { if (str == "") {     document.getelementbyid("txthint").innerhtml = "";     return; } else {     if (window.xmlhttprequest) {         // code ie7+, firefox, chrome, opera, safari         xmlhttp = new xmlhttprequest();     } else {         // code ie6, ie5         xmlhttp = new activexobject("microsoft.xmlhttp");     }     xmlhttp.onreadystatechange = function() {         if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {             document.getelementbyid("txthint").innerhtml = xmlhttp.responsetext;         }     }     xmlhttp.open("get","../action/subs/getcalls.php/?q="+str,true);     xmlhttp.send();     } } </script> </head> <body>  <form>  <select name="users" onchange="showuser(this.value)">    <option value="">select person:</option>    <option value="788">user 788</option>    <option value="786">user 786</option>    <option value="787">user 787</option>    <option value="789">user 789</option>  </select>  </form> <br> <div id="txthint"><b></b></div>  </body> </html> 

** if replace

    <form>   <select name="users" onchange="showuser(this.value)">     <option value="">select person:</option>     <option value="788">user 788</option>     <option value="786">user 786</option>     <option value="787">user 787</option>     <option value="789">user 789</option>   </select>   </form> 

by

    <form>       <input name="users" onchange="showuser(this.value)"/>      </form> 

the table display few seconds , close

here getcall.php

<!doctype html> <html> <head> <style> table {     width: 100%;     border-collapse: collapse; }  table, td, th {     border: 1px solid black;     padding: 5px; }  th {text-align: left;} </style> </head> <body>  <?php   $q = intval($_get['q']);   include '../db/connect.php';  mysqli_select_db($con,"ajax_demo"); $sql="select * oz2ts_call_logs member_id = '".$q."'"; $result = mysqli_query($con,$sql);  echo "<table>  <tr>   <th>device id</th>   <th>title</th>   <th>note</th>   <th>status</th>   <th>case number</th>  </tr>";   while($row = mysqli_fetch_array($result)) {       echo "<tr>";       echo "<td>" . $row['device_id'] . "</td>";       echo "<td>" . $row['title'] . "</td>";       echo "<td>" . $row['description'] . "</td>";       echo "<td>" . $row['status'] . "</td>";       echo "<td>" . $row['case_number'] . "</td>";       echo "</tr>";    }    echo "</table>";    mysqli_close($con);    ?>    </body>    </html> 

the code working me, onchange applies if click out of input, maybe want change <input name="users" onchange="showuser(this.value)"/> <input name="users" onkeyup="showuser(this.value)"/>

also <script src="http://code.jquery.com/jquery-1.10.2.js" type="text/javascript"></script> belongs head


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -