I have problems when i tried to add the onchange function to the js file Onchange i got it from :https://www.w3schools.com/php/php_ajax_database.asp :

jQuery(document).ready(function($) { 
  $('select.Nom').chosen({ width:"50%" }).change(function showUser(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 (this.readyState == 4 && this.status == 200) {
                document.getElementById("txtHint").innerHTML = this.responseText;
            }
        };
        xmlhttp.open("GET","tableau.php?Nom="+str,true);
        xmlhttp.send();
    }
});
});

the tableau.php :

<?php


  $q = intval($_GET['Nom']);


  $query = "select Adresse, Nom from herboristes where Nom = '".$q."'";

  $result = mysqli_query($query);

$row = mysqli_fetch_array($result) {
echo $row['Adresse'];
  }
   }

   ?>

So what i need exactly is to display the Adresse information when i selct a name (Nom) From My dropdown list which i creat with this code :

<select class='Nom' onchange="showUser()" name='Nom' id='Nom'>
<option value="">--- Select ---</option>

[insert_php]
$servername = "localhost";
$username = "root";
$password = "";
$conn = new mysqli($servername, $username, $password, "somapam_bd");

 $sql = mysqli_query($conn, "SELECT Nom FROM herboristes");

while($ligne_liste=mysqli_fetch_array($sql)) {
    echo '<option value="'.$ligne_liste['Nom'].'">'.$ligne_liste['Nom']."</option>n";
}
echo '</select>';
[/insert_php]
<div id="txtHint"><b>Person info will be listed here...</b></div>

I am using the chosen plugin wordpress for the dropdown list… it’s very complicated with wordpress and i really need your help.
thank you

Read more here: add onchange function to the chosen jquery wordpress


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: