0

I have next scripts:

test.php - in header I have:

<script>
function dest(str2) {
    if (str2 == "") {
        return;
    } else {
        //alert(str2);
        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("destin").innerHTML = xmlhttp.responseText;
                alert(xmlhttp.responseText);
            }
        }
        xmlhttp.open("GET","dest.php?q2="+str2,true);
        xmlhttp.send();
    }
}
</script>

test.php - in body I have:

<div class="col-sm-12">
    <div class="form-group has-icon has-label selectpicker-wrapper">
    <label>De la</label>
    <?php
        $plecari=db_query("SELECT DISTINCT plecare from `pl_dest_pf` WHERE activ = 'activ' ORDER BY plecare");
    ?>
    <select class="selectpicker input-price" data-live-search="true" data-width="100%" data-toggle="tooltip" title="Select" name="plecare" id="dela" onchange="dest(this.value)">
    <?php
        while($rez_plecari = $plecari->fetch_assoc()){
    ?>
        <option value="<?php echo $rez_plecari['plecare']?>"><?php echo $rez_plecari['plecare']?></option>
    <?php } ?>
    </select>
    <span class="form-control-icon"><i class="fa fa-location-arrow"></i></span>
    </div>
</div>
<div class="col-sm-12">
    <div class="form-group has-icon has-label selectpicker-wrapper">
    <label>Pana la </label>
    <select id="destin" class="selectpicker input-price" data-live-search="true" data-width="100%" data-toggle="tooltip" title="Select" name="desti">
    </select>
    <span class="form-control-icon"><i class="fa fa-location-arrow"></i></span>
    </div>
</div>

dest.php:

<?php
session_start();
include('include/functions2.php');
$a=$_GET['q2'];
$destinatie=db_query("SELECT DISTINCT destinatie from `pl_dest_pf` WHERE plecare ='".$a."' AND activ = 'activ' ORDER BY destinatie ");
?>
<option value="">Selecteaza...</option>
<?php
    while($rez_destinatie = $destinatie->fetch_assoc()){
?>
<option value="<?php echo $rez_destinatie['destinatie']?>"><?php echo $rez_destinatie['destinatie']?></option>
<?php } ?>

My issue is that the values for 2nd select are returned, but not showed on 2nd select (I can see it only with alert command). May you please tell me where I have the mistake. Many thanks!

Michael
  • 13
  • 3
  • Can you put screenshot of `alert(xmlhttp.responseText);` popup window with all response message here? – Medet Ahmetson Atabayev May 03 '16 at 17:38
  • Known issue with `innerHtml()` on `select` elements. More info here: http://stackoverflow.com/questions/3496797/javascript-ie-innerhtml-of-select or here http://stackoverflow.com/questions/2738254/javascript-innerhtml-not-working-with-html-select-menus – andreivictor May 03 '16 at 17:38
  • The alert response is: – Michael May 03 '16 at 17:41
  • @andreivictor, thank you for answer, but I'm not able to modify my scripts based on the solution you provided. may you please help me with the changes? it will be really appreciated. thank you! – Michael May 03 '16 at 17:50
  • Sorry, I don't have time right now to write an extended answer. From my point of view, the simplest solution is to use jQuery and then use it like: `$('#destin').html('.. your ajax response here...');` – andreivictor May 03 '16 at 18:51
  • Thank you. I will give it a try. – Michael May 03 '16 at 18:57

0 Answers0