doqs8936
2014-09-15 17:40
浏览 37
已采纳

yii dropdownlist change jquery仅在create中有效

i have form with render partial in yii which make update and create

i write this jquery code to check success only :

$("#AmakenPlaces_place_main_category").change(function()
{
alert("hi");
}

it works good to me in create but in update nothing do

i think this error because i get select value from database can any one help me .. iam tired to solve this problem

note: i use this code for main categories and sub categories for my site

my html in update

<div class="controls col-sm-6">                             
<select class="form-control" name="AmakenPlaces[place_main_category]" id="AmakenPlaces_place_main_category">
<option value="">Select main category</option>
<option value="1" selected="selected">cafe and resturants</option>
<option value="2">men and wommen</option>
<option value="3">hoho</option>
</select>                       
</div>

my code in javascript

  <script type="text/javascript">
            $(document).ready(function()
            {
            $("#AmakenPlaces_place_main_category").change(function()
            {
            var id=$(this).val();

            $.ajax
            ({
            type: "POST",
            url: '<?php echo yii::app()->createAbsoluteUrl("site/subcategory");?>',
            data: "id="+id,
            dataType: 'json',
            cache: false,
             success:function(data,textStatus,jqXHR)
            {
                $("#AmakenPlaces_place_sub_category").html('');
                $("#AmakenPlaces_place_sub_category").append('<option selected="selected">--Select Sub category--</option>');

                $.each(data.town,function(i,v) 
                {

                  $("#AmakenPlaces_place_sub_category").append('<option value='+v.id+'>'+v.name+'</option>');
                });


            }, 
            });
            });

            });
    </script>
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • douwen8424 2014-09-16 15:59
    最佳回答

    thanks all for attention my solve to this problem when i delete

    $(document).ready(function()
    {
    }
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题