2014-09-16 2 views
1

두 개의 드롭 다운 (그룹 ​​및 하위 그룹)이 있습니다. 그룹이 변경되면 하위 그룹을 새 그룹의 하위 목록 인 새 목록으로 업데이트하려고합니다. 여기 CodeIgniter - JQuery가 form_dropdown을 업데이트하지 않는 이유

는 드롭 다운 내 코드입니다 :

<div id="inp_p_group"class="control-group"> 
    <label class="control-label">Select Group:</label> 
    <div class="controls"> 
    <?php 
    $p_groups = array(); 
    $p_groups['-1'] = 'no selection'; 
    foreach ($groups->result() as $g_row){ 
     $p_groups[$g_row->tbl_group_id] = $g_row->vch_group_name; 
    } 
    echo form_dropdown('p_groups', $p_groups, $row->fk_group_id, 'style="width: 140px; font-size: 13px" id="p_groups"'); 
    ?> 
    </div> 
</div>  

<div id="inp_p_groupsub"class="control-group"> 
    <label class="control-label">Select Sub Group:</label> 
    <div class="controls"> 
    <?php 
    $p_groupsub = array(); 
    $p_groupsub['-1'] = 'no selection'; 
    foreach ($sub_groups->result() as $s_row){ 
     $p_groupsub[$s_row->tbl_group_sub_id] = $s_row->vch_sub_name; 
    } 
    echo form_dropdown('p_groupsub', $p_groupsub, $row->fk_group_sub_id, 'style="width: 140px; font-size: 13px" id="p_groupsub"'); 
    ?> 
    </div> 
</div>  

그리고 이것은 내가 내 인생이 어떤을 작동하지 않는 이유를 알아낼 수 없습니다 내 JScript 코드

$('#p_groups').change(function() { 
    var select = document.getElementById("p_groups"); 
    var myvalue= $.trim(select.options[select.selectedIndex].innerHTML); 
    // now populate the Sub Group selector with the children of the selected Group 
    group_id = select.options[select.selectedIndex].value; 
    // make call to function to get the sub-group data 
    $.post(
     "../product_controller/get_subgroup_json",// function call 
     {'gid' : group_id},       // function data 
     function (retval) {       // callback function 
      //var sub_list = document.getElementById("p_groupsub"); 
      var sub_list = $('#p_groupsub')[0]; 
      sub_list.options.length = 0; // this removes existing options 
      $.each(retval, function(index, element) { 
       // create an Option object 
       var opt = document.createElement("option"); 
       // Add an Option object to Drop Down/List Box 
       sub_list.options.add(opt); 
       // Assign text and value to Option object 
       opt.value = index; 
       opt.text = element; 
      }); 
     }, // end callback 
     "json" 
     ); // end post 
}); // end p_groups-change function 

입니다 도움이 크게 감사합니다.

G.

UPDATE 나는 더이 lookinginto 봤는데 나는 같은 일을 할 수있는 사이트의 다른 부분에서 같은 JS를 사용합니다. 두 곳 모두에서 함수를 호출합니다.

"../product_controller/get_subgroup_json" 

하위 그룹 목록을 반환하려면 다음을 수행하십시오.

../index.php/product_controller/product_controller/get_subgroup_json?gid=12 
: 나는 POST 헤더 작동되는 코드에서 호출 Wehn ​​

../index.php/product_controller/get_subgroup_json?gid=12 

하지만 작동하지 않는 코드에서 호출 할 때 POST의 모습처럼 보인다

JS는 두 경우 모두 동일하므로 여분의 'product_controller /'가 어디서 나올지 알 수 없습니다.

G.

+0

코드는 부트 스트랩 2.0을 사용하는 http://jsfiddle.net/ –

+0

에 PHP 코드 결과 (HTML)와 JS를 넣습니다. jsfiddle에서이 작업을 하시겠습니까? 나는 그것을 사용하는 경험이 없다. – unplugngo

+0

좋아, 제 생각에는 jsfiddle에서 작동하고 있다고 생각합니다 - 여기 : http://jsfiddle.net/unplugngo/ab9gqxLt/ – unplugngo

답변

0

여기서 문제는 다음과 같습니다 서브 그룹 드롭 다운의 데이터를 가져 오는 기능, 호출에 :보기는 product_controller에서 호출

$.post(
    "../product_controller/get_subgroup_json", // function call 

때문에,이 라우팅은 더 이상 함수 호출에서 암시, 그래서 호출해야합니다 :

$.post(
    "../get_subgroup_json", // function call 

나는 그것이 URI 어딘가에 오류가 발생하지 않았다 정말 이상한 생각, 그래서 좋겠 누군가 나에게 의견을 주려고이 문제에 대한 아이디어가 있다면 고맙겠습니다.

다시 찾아 주셔서 감사합니다.

U.

관련 문제