Jquery Autocomplete won't accept my variable
I have some issue with my jquery autocomplete. My scenario is like this, I have a dropdown and that dropdown defines which type of class should be displayed in the autocomplete. E.g. the dropdown sets the type to 1 or 2 or 3 or 4. The autocomplete should get this value and pass it to the sql so it will display the right class in the autocomplete according to t the type.
My issue is that the autocomplete does not get the type so it will display all data and does not filter it on the type.
This is my code:
$("#textinput").autocomplete("getclass.php?func=getClass&type="+ $("#type").val(), {
minChars: 1,
delay: 400,
width: 260,
selectFirst: true,
max: 10,
}).result(function (event, data, formatted){
if(data)
{
开发者_开发问答 $("#textinput").val(data[1]);
}
});
You're not selecting the option value properly. Try this:
$("#textinput").autocomplete("getclass.php?func=getClass&type="+ $('#type option:selected').val(), {
minChars: 1,
delay: 400,
width: 260,
selectFirst: true,
max: 10,
}).result(function (event, data, formatted){
if(data)
{
$("#textinput").val(data[1]);
}
});
精彩评论