javascript - Dynamic drop down using PHP JQuery and JSON -
i trying create dynamic drop down menu using data parsed json file , stored in array in php. trying use jquery data not know going wrong.
<?php require './index.php'; ?> <!doctype html><head><meta charset='utf-8'> <title>dropdown</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> $(function() { alert('<?php echo$city_list; ?>'); $("#json-one").change(function() { var $dropdown = $(this); $.getjson("demo2.php", function(data) { var key = $dropdown.val(); var vals = []; switch(key) { case '<?php echo $city_list;?>': vals = data.split(","); break;} var $jsontwo = $("#json-two"); $jsontwo.empty(); $.each(vals, function(index, value) { $jsontwo.append("<option>" + value + "</option>"); });});});}); </script></head><body> <div id="page-wrap"> <h1>pulls json</h1> <select id="json-one"> <option selected value="base">please select</option> <option value="id1"><?php echo $city_list;?></option> </select> <br /> <select id="json-two"> <option>please choose above</option> </select> </div></body></html>
i got data $city_list
contains 1 value @ present.
array.php
<?php require 'index.php'; header('content-type: application/json'); echo json_encode($list);
output of [["hil",[125,139]],["mer",[52,52]]]
. planning when select city dropdown box above hil
, mer
second dropdown should created. , if select of corresponding values should displayed.
any on appreciated.
create dom elements additional dropdown in html markup (i.e select , containers), hide them default add select options (via jquery) based on first choice, unhide elements.
Comments
Post a Comment