0
votes

I'm having a problem setting the value on multiple jQuery autocomplete combobox's.

I'm using the following code to select a value. This works well if there is only one combobox but if more than one it changes the value on multiple combobox's.

            $('.ui-autocomplete-input').focus().val(memberData.clubName);
            $('.ui-autocomplete-input').autocomplete('close');

Is there a way to make a combobox unique?

Here is the jQuery in full:

$('.amendButton').live('click', function() { var id = $(this).attr('rel');

        $.ajax({
        type : 'POST',
        url : 'php/membershipProcessor.php',
        dataType : 'json',
        data: {
            membershipID : id,
            getMembership : "getMembership",
        },
            success : function(memberData){

            $('#amendMembershipID').val(id),

            $('#amendClubName').focus().val(memberData.clubName);
            $('#amendClubName').autocomplete('close');


        },
            error : function(memberData){
            alert(data.msg);
        }

    });
    return false;
}); 
3
In what context are you using this code? IDs are a good way of making them unique, but if you subscribe with some click event, it is sometimes possible to just use $(this) - Marnix

3 Answers

0
votes

Yes, you must use an id instead of a class when you select it programmatically (a jquery selector with an id always return only one value):

 $('#yourid').focus().val(memberData.clubName);
 $('#yourid').autocomplete('close');

Give your combobox unique ids and you should be okay

0
votes

You need to add a specific class, or access by ID, or by navigation to route to just the one you want. Maybe if you post some more code, it would help us make more specific suggestions.

0
votes

you can give the 'combobox' an id, then use that to select it

OR

you can use jquery's .eq() to select a specific one