Setting a value on multiple jquery autocomplete combobox's
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 开发者_JS百科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;
});
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
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.
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
精彩评论