2017-04-11 2 views
0

두 가지 옵션이 있습니다. 선택을 변경할 때 ... 다른 데이터베이스를 필터링/자동 완성하려고합니다. http://aehlke.github.io/tag-it/이 없으면 자동 완성 기능이 소스를 변경하지만 ... 콘솔에서 테스트 소스 01이 테스트 소스 02로 변경되었음을 알 수 있지만 source_01.php에 머물러 있습니다. 원인은 무엇입니까?자바 스크립트 - 선택 옵션으로 태그 지정 소스 변경

HTML :

<select id="search_database" class="form-control"> 
    <option value="1" selected="">Source 01</option> 
    <option value="2">Source 02</option> 
</select> 

자바 스크립트 :

$('#search_database').on('change', function() { 
    if ($('#search_database').val() == 1) { 
     console.log('Test Source 01');   


     $("#input-newsearch").tagit({ 
      ... 
      autocomplete: ({ 
        source: function(request, response) { 
        ... 
        $.ajax({ 
         url: "/source_01.php", 
         ... 
        }); 
        },       
        ... 
       }) 

      }); 


    } else if ($('#search_database').val() == 2) { 
     console.log('Test Source 02');   

     $("#input-newsearch").tagit({ 
      ... 
      autocomplete: ({ 
        source: function(request, response) { 
        ... 
        $.ajax({ 
         url: "/source_02.php", 
         .. 
        }); 
        },       
        ... 
       }) 
      });   

    } 

}); 

답변

0

귀하의 문제는 당신이 변경된 옵션의 값을 선택하려는 경우이 옵션을 변경할 때 스크립트에 의해 포착 가져 오지 값입니다 당신은 아래 코드와 비슷한 것을해야합니다.

HTML :

<label for="clientSelect" style="margin-left:14px;">Client:</label> 
    <select name="clientSelect" id="clientSelect" onChange="clientId(this.id)" style="width:180px;"></select> 
    <input type="text" id="clintId" size="1" hidden> 

자바 스크립트 :

function getClient(cId){ 
    //Get the selected ID using this.is in client side HTML then breaks it up using this to get the ID only 
      var select = document.getElementById("catSelect"), 
      optionId = select.options[select.selectedIndex], 
      catId = optionId.id; 

나는 데이터베이스에 다음 내 PHP 선택한 ID를 보낼 제기 숨겨진 텍스트를 사용합니다.

관련 문제