i cant seem to get my json data into a selection box. here my code for the dropdown.php

</head>

<script src="jquery.js"></script>
<script src="jquery.jCombo.js"></script>
<style type="text/css">
</style>

<?php
$directory = opendir("C:/xampp/htdocs/SE3S604CW3/xml");

$storeFilesIntoArray[] = "please select XML to load";

while (($fileName = readdir($directory)) !== false)
{
 $getLastFourDigitsOfFile = substr($fileName,-4); 

 if($getLastFourDigitsOfFile == ".xml")
 {
  #echo "filename is " . $fileName . "<br/>";
    $storeFilesIntoArray[] = $fileName;
 }
}
$json = json_encode($storeFilesIntoArray);
echo $json;
closedir($directory);

?>

</script>

<body>

</body>
</html>

which shows the following;

["please select XML to load","cd_catalog.xml"]

here on my main.php page when ive done this bit of code, nothing seems to be happening, am quite new to doing these callback functions.

<script src="jquery.js"></script>
<script src="jquery.jCombo.js"></script>
<style type="text/css">

</style>

<script type="text/javascript">

$(document).ready(function(){
    $.getJSON("dropdown.php", function(data){
        var select = $('#list1');
        if (select.prop){
            var options = select.prop('options');
        }
        else{
            var options = select.attr('options');
        }
        $('option', select).remove();
        $.each(data, function(key, value){
            options[options.length] = new Option(value['name'], value['id']);
        });

    });

});
</script>
<body>
<select name="list1" id="list1"></select><br><br>
</body>
</html>

hope someone can help me figure out where ive gone wrong :)

Member Avatar for LastMitch

hope someone can help me figure out where ive gone wrong :)

This issue you are having is not really related to PHP even though you post a few lines. This is more like a Ajax issue rather a php/mysql issue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.