Reputation: 987
Hi I'm trying to implement some JQuery to use the Autocomplete UI. I have a drop down list with two options. Actor and Film. Depending on what is selected, I would like the source for the autocomplete input box to be different. Is there anything wrong with the JQuery I have?
<script type="text/javascript">
$(document).ready(function(){
$("#selectType").change(function() {
if ($(this).val() == "Actor"){
$("#tags").autocomplete({
source: "nameSearch.php",
minLength: 2
});
}
else if($(this).val() == "Film"){
$("#tags").autocomplete({
source: "FilmSearch.php",
minLength: 2
});
}
});
});
</script>
Upvotes: 0
Views: 214
Reputation: 14025
Use like this:
$(document).ready(function () {
//Create widget with default data source
$("#tags").autocomplete({
source: "nameSearch.php",
minLength: 2
});
$("#selectType").change(function () {
// Assign new data source like that :
if ($(this).val() == "Actor")
$("#tags").autocomplete("option", "source", "nameSearch.php");
else
if ($(this).val() == "Film")
$("#tags").autocomplete("option", "source", "FilmSearch.php");
// And what is your 2 conditions are not met?????
});
});
Upvotes: 2