Now, the basic things you want to do with said select statement:
1. Get the value of the selected item in the province combobox.
2. clear the value option in the region combobox.
3. add new value by the province
and now we will to make combobox about province and region,, in the indonesia we have many province that have many regions too. and we have a combobox id
<select name=”member_province” id=”member_province”>
<option selected=”selected” value=”34″>-</option>
<option value=”5″>Yogyakarta</option>
</select>
and how jquery to load json data ???
jquery have a function to read json data : getJSON
$(document).ready(function(){
$(“#member_province”).click(function(event){
if($(this).val()!=”){
$(“#member_region”).empty();
$.getJSON(“http://toespconer.wordpress.com/regionbyprovince/”+$(this).val(), function(data) {
$.each(data, function(key, val) {
$(“#member_region”).append(” + val.region_name + ”);
});
});
}
});
});
and when we select yogyakarta province we have a result json like this :
[
and combobox region will automaticly change the value :{"region_id":"3","region_name":"Kota Yogyakarta","province_id":"5","region_date":"2012-05-07 09:22:47"},{"region_id":"4","region_name":"Sleman","province_id":"5","region_date":"2012-05-07 09:22:47"}]
No comments:
Post a Comment
Jika ada kesalahan silahkan tulis dalam kotak komentar dan terimakasih.