4

I have an input field and a hidden div. The input is readonly. When the user clicks the input, a list of items is proposed using the JQuery UI autocomplete. What I would like and do not manage to achieve, is to trigger an event (removing the hidden class) when the user selects an item from the list. Hope someone can help. Thank you in advance for the replies. Cheers. Marc.

http://jsfiddle.net/fdBHC/1/

My html:

<input id="conditions" type="text" readonly="readonly" /input>
<div id="test" class="hidden">some text</div>​

My css:

input{
    margin:50px;
    border:1px solid black;}

div{
    width:200px
    height:200px;
    background-color:orange;}

.hidden{
    display:none;}

My js:

$(function() {
    var availableTags = [
            "aucune","Prise de contact préalable nécessaire"
        ];
    $("#conditions").autocomplete({
        source: availableTags,
        minLength: 0
    }).click(function() {
        $(this).val("");
        $(this).autocomplete("search");
    });
});​

2 Answers 2

7

There is an event in autocompleter which you can use (if I understand correctly):

$("#conditions").autocomplete({
    source: availableTags,
    minLength: 0,
    select: function(event, ui) {
        // do something when an item from the list is selected, for example:
        $('#test').remove();
    }
})...
Sign up to request clarification or add additional context in comments.

1 Comment

You are missing a comma after minLength: 0
0

you truly saved me after searching, trying , testing fails for more than 1 hour. Thanks a lot. I used it this way $("#farmer").autocomplete({ select: function(event, ui) { alert('youve just selected a farmer, thanks'); } })

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.