Expert Refresh

Combobox related

Ajax

Request
Ajax post
Ajax cross domain
Autocomplete
Combobox related


0.0% 100%
0 pages 29 questions
Remove combobox options






<?php if ($county = @$_GET['county']) { $arr = array( 'County_1' => array(0=>"", 11=>"City_11", 12=>"City_11"), 'County_2' => array(0=>"", 21=>"City_21", 22=>"City_22"), ); echo json_encode($arr[$county]); die; } ?> <form method="post"> <select id="county" onchange="setCity();"> <option> <option>County_1 <option>County_2 </select> <select name="city" id="city" disabled="disabled"> <option value="" label="City">City</option> </select> </form> <script src=""></script> <script type='text/javascript'> function setCity(){ var county = $('select#county option:selected').val(); //alert(county); if (county) { $("#city option").each(function() { $(this).remove(); // -- Look Here -- // }); $('#city').removeAttr('disabled'); } $.get("test.php?county="+county, function (data){ var obj = jQuery.parseJSON(data); $.each(obj, function(key, val) { //console.log(key); $('#city').append($("<option></option>").attr("value",key).text(val)); // -- Look Here -- // }); }); } </script>


References



n/a