Ignore:
Timestamp:
Apr 23, 2015 12:00:06 PM (10 years ago)
Author:
namnd
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pro-violet-viettel/sourcecode/application/modules/frontend/views/user_infor.php

    r883 r906  
    2626            <label for="form-field-username" class="col-sm-4 control-label no-padding-right">Tỉnh / Thành phố</label>
    2727            <div class="col-sm-8">
    28                 <select name="province" id="form-field-province" class="form-field-province col-xs-12 col-sm-10">
     28                <select name="province" id="form-field-province" class="form-field-province-user col-xs-12 col-sm-10">
     29                                        <option></option>
    2930                    <?php foreach ($provinces as $key => $pro): ?>
    3031                        <option value="<?php echo $key; ?>" <?php if ($user['province'] == $key) echo "selected"; ?>><?php echo $pro; ?></option>
     
    3839                        <label for="form-field-username" class="col-sm-4 control-label no-padding-right">Quận / Huyện</label>
    3940                        <div class="col-sm-8">
    40                                 <select name="district" id="form-field-district" class="form-field-district col-xs-12 col-sm-10">
     41                                <select name="district" id="form-field-district" class="form-field-district-user col-xs-12 col-sm-10">
    4142
    4243                                </select>
     
    6061var district_id = "<?php echo $user['district']; ?>";
    6162var province_id = "<?php echo $user['province']; ?>";
     63
    6264$(document).ready(function(){
    63         $(".form-field-province").change(function(){
     65        $(".form-field-province-user").change(function(){
    6466                changeEventProvince(province_id);
    6567        });
    66         if ($(".form-field-province").val() !== 'undefined'){
     68        if ($(".form-field-province-user").val() !== 'undefined'){
    6769                checkSelectedDistrict(province_id);
    6870        }
    6971});
     72
     73function changeEventProvince(provinceId){
     74        $(".form-field-district-user").html("");
     75        $.ajax({
     76        url: '/frontend/user/getDistrict/' + provinceId,
     77        type: 'POST',
     78        success: function (data, textStatus, jqXHR)
     79        {
     80            result = jQuery.parseJSON(data);
     81                        content = "<option></option>";
     82                        if (result != null){
     83                                for (var i in result){                 
     84                                        content = content + '<option value="' + result[i].district_id + '">'+ result[i].type + " "  + result[i].district_name + '</option>'
     85                                }
     86                        }
     87                        $(".form-field-district-user").html(content);
     88        }
     89    });
     90}
     91
     92function checkSelectedDistrict(provinceId){
     93        $.ajax({
     94        url: '/frontend/user/getDistrict/' + provinceId,
     95        type: 'POST',
     96        success: function (data, textStatus, jqXHR)
     97        {
     98            result = jQuery.parseJSON(data);   
     99                        content = "<option></option>";
     100                        if (result != null){
     101                                for (var i in result){
     102                                        if (result[i].district_id === district_id){
     103                                                content = content + '<option value="' + result[i].district_id + '" selected >' + result[i].type + " " + result[i].district_name + '</option>';
     104                                        }else{
     105                                                content = content + '<option value="' + result[i].district_id + '">' + result[i].type + " "  + result[i].district_name + '</option>';
     106                                        }
     107                                }
     108                               
     109                        }
     110                        $(".form-field-district-user").html(content);
     111        }
     112    });
     113}
    70114</script>
Note: See TracChangeset for help on using the changeset viewer.