How to clear autocomplete selected values?

I have a page with several JQuery autocompletes. I have implemented a button to clear all selected values, but it does not work... I have tried to set $(...).text(""); but it does not work. Firebugs fails on the line and does not throw any error message. It quits the function.

What is the right way to clear the selected value of JQuery autocompletes, from code?

Upvotes: 6

Views: 27060

Answers (4)

Shobhit Sharma
Shobhit Sharma

Reputation: 493

You should use this one, it'll work

$("selector").autocomplete({
            source: ,
            delay: 200,
            minLength: 3,                
            select: function (event, ui) {                    
               ui.item.value = "";  // it will clear field 
                return false;
            }
        });

Upvotes: 3

yarg
yarg

Reputation: 709

You should use:

$('selector').autocomplete('close').val('');

This will also reset the current search of the autocomplete (in addition to clearing the input).

Upvotes: 13

Avinash
Avinash

Reputation: 801

Try this,

$("selector").autocomplete({
                source: ,
                delay: 200,
                minLength: 3,                
                select: function (event, ui) {                    
                    $(this).val() = "";
                    return false;
                }
            });

Upvotes: -5

Hemesh Singh
Hemesh Singh

Reputation: 1165

Try using $(...).attr("value","");

Hope it works!! Sorry if i have misunderstood the question.

Upvotes: 4

Related Questions