0

I'm using the JQuery auto complete ( jquery.autocomplete.js ). and I'm wondering how can I submit a form once an item has been selected? currently when an item is select you have to hit enter twice, once to get the item into the search field, and once to submit the search. I'd like to submit the search on the first enter or when an item selecting by mouse.

how can I use this to submit the form???? This is my code::

$(function() {
     $("#artist" ).autocomplete({
     source: function( request, response ) {
            $.ajax({
                url: "http://",
                dataType: "jsonp",
                data: {
                    results: 12,

                    format:"jsonp",
                    name:request.term
                },

THis is the form::

<form id="mainSearchForm" onSubmit="ytvbp.listVideos(this.queryType.value, this.searchTerm.value, 1); document.forms.searchForm.searchTerm.value=this.searchTerm.value; ytvbp.hideMainSearch(); document.forms.searchForm.queryType.selectedIndex=this.queryType.selectedIndex; return false;">
       <div align="left">
         <select name="queryType" onChange="ytvbp.queryTypeChanged(this.value, this.form.searchTerm);">
           <option value="all" selected="true">All Videos</option>
           <option value="top_rated">Top Rated Videos</option>
           <option value="most_viewed">Most Viewed Videos</option>
           <option value="recently_featured">Recently Featured Videos</option>

         </select>
         <input name="searchTerm" id="artist" >
         <input type="submit" value="Search">
       </div>
       </form>
4

2 回答 2

5

您尚未发布自动完成代码或表单代码,因此我不知道您希望任何人如何为您量身定制答案。但是,您只需要将某些内容绑定到 select 事件。这应该这样做:

$('#whatever').autocomplete({
    select: function() {
        $(this).closest('form').trigger('submit');
    }
});

文档在这里。

于 2012-05-18T09:35:11.733 回答
0

you can use select function like this, Select Event in Autocomplete

$( "#yourID" ).autocomplete({
        source: "YourUrl.php",
        minLength: 2,
        select: function( event, ui ) {
            log( ui.item ?
                "Selected: " + ui.item.value + " aka " + ui.item.id :
                "Nothing selected, input was " + this.value );
                             // you can replace this and put the submit code. by calling submit() method. 
                       $(this).closest('form').trigger('submit');

        }
    });
于 2012-05-18T09:34:14.073 回答