2017-12-13 5 views
0

asp.netのデータベースからドロップダウンリストのSelected Valueに対してjQueryオートコンプリートテキストボックスを設定するにはどうすればよいですか?ドロップダウンリストの選択ごとにオートコンプリートで値を表示します。ここに私のコードは、私がドロップダウンリストで値を選択するとき、それは私が間違って行われ、どのように私は私が私が合格し、私の問題を解決しjquery AutoCompleteテキストボックスの値をDropdownlistのSeleted値と比較して

var ddl = document.getElementById('<%=cmbSourceCode.ClientID %>'); 
$(function() { 

    $("[id$=txtCode]").autocomplete({ 
     source: function (request, response) { 
      $.ajax({ 
       url: '<%=ResolveUrl("xCreate_grn.aspx/GetSourceCode") %>', 
       data: "{ 'prefix': '" + request.term + "','code':'"+ddl.SelectedIndex+ "'}", 
       dataType: "json", 
       type: "POST", 
       contentType: "application/json; charset=utf-8", 
       success: function (data) { 
        response($.map(data.d, function (item) { 
         return { 
          label: item.split('-')[0], 
          val: item.split('-')[1] 
         } 
        })) 
       }, 
       error: function (response) { 
        alert(response.responseText); 
       }, 
       failure: function (response) { 
        alert(response.responseText); 
       } 
      }); 
     }, 
     minLength: 4, 
     focus:function(event,ui){ 
      event.preventDefault(); 
      this.value = ui.item.label; 
     } 

    }); 
}); 
+1

'[id $ = txtCode]' =>これが正しいセレクタだと確信していますか?ターゲットURLでリクエストが解決されたことを確認するために、コンソールとチェックネットワークのタブにエラーが表示されましたか? –

+0

コンソールでエラーが発生しない – Raheel

答えて

0

ドロップダウンselectindexchangeイベントにサービスを呼び出すことができる場所私は知らないWebサービスを呼び出すことはできませんです私のコードでこれを使用した後、私の関数が正常に動作していないように誤ってドロップした値を選択しました

$("[id$=txtCode]").autocomplete({ 
     source: function (request, response) { 
      $.ajax({ 
       url: '<%=ResolveUrl("xCreate_grn.aspx/GetSourceCode") %>', 
       data: "{ 'prefix': '" + request.term + "','code':'"+ 
          $('select[id=cmbSourceCode]').val() + "'}", 
       dataType: "json", 
       type: "POST", 
       contentType: "application/json; charset=utf-8", 
       success: function (data) { 
        response($.map(data.d, function (item) { 
         return { 
          label: item.split('~')[0], 
          val: item.split('~')[1] 
         } 
        })) 
       }, 
       error: function (response) { 
        alert(response.responseText); 
       }, 
       failure: function (response) { 
        alert(response.responseText); 
       } 
      }); 
     }, 
     minLength: 4, 
     focus:function(event,ui){ 
      event.preventDefault(); 
      this.value = ui.item.label; 
     } 

     } 
    }); 
}); 
関連する問題