Noam
Noam

Reputation: 3391

setting jquery auto-complete plugin to auto-submit

Two things I'm trying to adjust in my usage of JQuery autocomplete in PHP.
1. I would like that when I chose an option it will auto-submit the form (currently it requires two enters)
2. When I continue to write and no new options exist is still shows me the old options. I would rather it not suggest un-relevant options even if none exist.

Thanks

UPDATE: I've resolved num. 2, for future readers the problem was I sent null instead of an empty json from the source url. Regarding num. 1, I've done as suggested and now my JQuery js code looks like this:

$( "#searchid" ).autocomplete({
    source: "/autocomplete_url.php?more=1",         
});

$("#searchid").result(function (event, data, formatted) 
{
    alert("o"); // just to check if got here
    $('#formid').submit();
});

However, The result function is never invoked (I've added a simple alert to verify that). Any idea why?

Upvotes: 1

Views: 970

Answers (1)

Dhruva Sagar
Dhruva Sagar

Reputation: 7307

For 1.) you can simply submit the form through jquery from within the result(handler). Look at this - http://docs.jquery.com/Plugins/autocomplete if you look at the last code sample on the page, instead of redirecting, you can simply submit the form instead within the result call.

Regarding the 2.) point, well jquery autocompletes works just like that, perhaps you're doing something wrong or expecting something wrong, please give more information regarding the same.

Upvotes: 1

Related Questions