Jump to content

Recommended Posts

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>

  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
  <div id="txtHint"></div>
  <script>
        function showUser(str) {
            //  alert (str);

            if (str == "") {
                document.getElementById("txtHint").innerHTML = "";
                return;
            } else {
                if (window.XMLHttpRequest) {
                  
                    // code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp = new XMLHttpRequest();
                } else {
                    // code for 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", "new.php?q=" + str, true);
                xmlhttp.send();
            }
        }
    </script>


<body>
    <form>


        <select onchange="showUser(this.value)">

            <option value="1" >
                1
            </option>

            <option value="3" >
                3
            </option>


        </select>


        <?php
        $con = mysqli_connect("localhost", "root", "");
        mysqli_select_db($con, "crud_tutorial");

        if (isset($_REQUEST['q'])) {
            $q = intval($_GET['q']);


//echo "$q";


            $sql = "SELECT * FROM customers WHERE id = '" . $q . "'";
            $result = mysqli_query($con, $sql);
        } else {


            $sql = "SELECT * FROM customers ";
            $result = mysqli_query($con, $sql);
        }
        echo "<table>
<tr>
<th>id</th>
<th>name</th>

</tr>";
        while ($row = mysqli_fetch_array($result)) {
            echo "<tr>";
            echo "<td>" . $row['id'] . "</td>";
            echo "<td>" . $row['name'] . "</td>";


            echo "</tr>";
        }
        echo "</table>";
        mysqli_close($con);
        ?>
    </form>
</body>

</html>
 

Can you elaborate a little please?

thnkx scootstah , i have created drop down and i want to filter my html table by selecting the  dropdown , but when i select the drop down it create 2 html table ,, but i need one html table , thanks

So the PHP script you are calling must be returning an HTML table, and then you're adding that to <div id="txtHint"></div> with this line:

document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
Is the code you posted the script that you're calling with AJAX?

So the PHP script you are calling must be returning an HTML table, and then you're adding that to <div id="txtHint"></div> with this line:

document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
Is the code you posted the script that you're calling with AJAX?

 

yes its ajax

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.