Javascript-使用select选项更改标记it源代码

Javascript-使用select选项更改标记it源代码,javascript,jquery,tag-it,Javascript,Jquery,Tag It,我有一个选择,有两个选项。更改“选择”选项时。。。我想筛选/自动完成另一个数据库。如果没有,它工作正常,自动完成正在更改源。。。但不是用它。它保持在source_01.php,尽管我在控制台中看到Test source 01更改为Test source 02。这可能是什么原因造成的 HTML: 您的问题是,当您更改选项时,脚本没有拾取值。如果您要拾取更改选项的值,则必须执行类似于以下代码的操作 HTML: 我使用隐藏文本字段将所选ID发送到我的PHP,然后发送到数据库 <select id

我有一个选择,有两个选项。更改“选择”选项时。。。我想筛选/自动完成另一个数据库。如果没有,它工作正常,自动完成正在更改源。。。但不是用它。它保持在source_01.php,尽管我在控制台中看到Test source 01更改为Test source 02。这可能是什么原因造成的

HTML:


您的问题是,当您更改选项时,脚本没有拾取值。如果您要拾取更改选项的值,则必须执行类似于以下代码的操作

HTML:

我使用隐藏文本字段将所选ID发送到我的PHP,然后发送到数据库

<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",
                        ..
                    });
                  },                        
                    ...
                })
            });         

    } 

}); 
<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;