2013-03-19 76 views
1

提交我找到了一個片斷,增加了自動完成的表格:JQuery的選擇上

http://jsfiddle.net/XxTuA/2/

的問題是,我無法弄清楚如何提交上選擇的形式。任何幫助將不勝感激:

var suggestCallBack; // global var for autocomplete jsonp 

$(document).ready(function() { 
    $("#search").autocomplete({ 
     source: function(request, response) { 
      $.getJSON("http://suggestqueries.google.com/complete/search?callback=?", 
       { 
        "hl":"en", // Language     
        "jsonp":"suggestCallBack", // jsonp callback function name 
        "q":request.term, // query term 
        "client":"youtube" // force youtube style response, i.e. jsonp 
       } 
      ); 
      suggestCallBack = function (data) { 
       var suggestions = []; 
       $.each(data[1], function(key, val) { 
        suggestions.push({"value":val[0]}); 
       }); 
       suggestions.length = 5; // prune suggestions list to only 5 items 
       response(suggestions); 
      }; 
     }, 
    }); 
}); 

回答

0

試試這個

$("#search").autocomplete({ 
    select: function (event, ui) { 
     var selectedObj = ui.item;    
      alert(selectedObj.value); 
      $("#search").val(selectedObj.value); 
     $('#formId').submit(); 
     }, 
     source: function(request, response) { 


................. 
+0

謝謝。它似乎部分工作。表單被提交,但與鍵入的文本,而不是與從自動建議中選擇的文本... – EliasP 2013-03-19 06:59:53

+0

@EliasP我改變了我的code.check這一次 – PSR 2013-03-19 07:02:12

+0

@EliasP你檢查了它 – PSR 2013-03-19 07:04:12