2012-03-14 1 views
0

が動作していない:jQueryのオートコンプリートを選択:関数は、これは非常にシンプルだが、まだ私はそれを動作させるように見えることはできません

var options, a; 
jQuery(function(){ 
    options = { 
    serviceUrl:'ajax/parts_by_partno.php', 
    select: function(event, ui) { 
    $("#hiddenId").val(ui.item.id); 
    } 
    }; 
    a = $('#fieldWithData').autocomplete(options); 
}); 

項目がオートコンプリートリストから選択されたら、私は#hiddenIdはそのを変更したいです選択した項目のIDに値:

$("#hiddenId").val(ui.item.id); 

私もちょうどこのような静的なものに#hiddenIdを変更しようとしました:

$("#hiddenId").val('test'); 

何も変更されていません。私は間違って何をしていますか?

+0

JavaScriptをエラーにしますか?あなたは火かき棒やクロムのdevのツールでチェックした – JIA

+0

火かき棒でエラーはありません。オートコンプリートは正常に機能していますが、#hiddenIdは変更されていません。 – Devin

答えて

0

は、それがここ

$('#selector').autocomplete({ 
    source: url, 
    select: function (event, ui) { 
     $("#txtAllowSearch").val(ui.item.label); // display the selected text 
     $("#txtAllowSearchID").val(ui.item.value); // save selected id to hidden input 
    } 
}); 

$('#button').click(function() { 
    alert($("#txtAllowSearchID").val(); // get the id from the hidden input 
}); 
+0

Firebugは私に$( '#fieldWithData')というエラーを表示します。オートコンプリートは関数ではありません。 – Devin

+0

このリンクをクリックすると、アイデアが得られます..... http://www.petefreitag.com/item/756.cfm –

0

は基本的に、あなたがたときに選択値コールバックを追加する必要がオートコンプリートモジュール

を使用する方法についてfull blog entryでのuを助けるこのcode..hopeの表情を持っています

select: function(e, ui) { 

     //create formatted friend 
     var friend = ui.item.value, 
      span = $("<span>").text(friend), 
      a = $("<a>").addClass("remove").attr({ 
       href: "javascript:", 
       title: "Remove " + friend 
      }).text("x").appendTo(span); 

      //add friend to friend div 
      span.insertBefore("#to"); 
     }, 

     //define select handler 
     change: function() { 

      //prevent 'to' field being updated and correct position 
      $("#to").val("").css("top", 2); 
     } 
    }); 
関連する問題