<title>Untitled Document</title>
</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;
//close directory and print the contents of the array to check if its working.
closedir($directory);
?>
<body>
<script type="text/javascript">
$(document).ready(function(){
$("#list1").jCombo($json, {} );
});
</script>
<select name="list1" id="list1"></select><br><br>
</body>
</html>
populating dropdown box with json data
Page 1 of 11 Replies - 180 Views - Last Post: 01 February 2013 - 01:58 PM
#1
populating dropdown box with json data
Posted 01 February 2013 - 07:59 AM
i have got this code so far but it don't seem to be doing what i need, i have followed a few examples but this is what ive done at top of my head. hope someone can help. just need to populate the table now
Replies To: populating dropdown box with json data
#2
Re: populating dropdown box with json data
Posted 01 February 2013 - 01:58 PM
You're mixing languages. A PHP variable cannot be directly referenced by Javascript, since PHP is server-side and Javascript is client-side. What you can do though is wrap the reference to $json in PHP tags and then echo it out so that it becomes part of the served Javascript. Try changing line 36 to this:
...or, if you are using PHP5.4+, you can use short tags:
$("#list1").jCombo(<?php echo $json; ?>, {} );
...or, if you are using PHP5.4+, you can use short tags:
$("#list1").jCombo(<?= $json ?>, {} );
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|