1st question
I have a dropdownlist, filled with countries (from xml file).
When you choose a country, you can use the autocomplete for a textbox. This autocomplete has postal codes from the choosen country.
Now I want to set the autocompl开发者_Go百科ete off right after the dropdownlist.change event for preventing that the autocomplete (filled with postal codes) for 1 country also work for another country. But how do you turn it off?
Code:
//when changing country, other postcodes will load
$('[id$=landenDropDown]').change(function () {
//autocompletes removal
...
$('[id$=POSTCODETextBox]').html("");
var LandCode = $('[id$=landenDropDown]').attr("value");
//autocomplete with postal codes for Belgium
if (LandCode == "BE") {
//autocomplete postcode from selected country
$('[id$=POSTCODETextBox]').autocomplete("PostcodeBE.aspx");
}
//autocomplete with postal codes for Holland
else if (LandCode == "NL") {
//autocomplete postcode from selected country
$('[id$=POSTCODETextBox]').autocomplete("thingXml.aspx");
}
else {
//test
getal += 1;
alert(getal);
}
The problem is when the autocomplete is finished and select an other country that this autocomplete still exist, even when it doesnt have to show up.
Please view the documentation: (Doc)
$( ".selector" ).autocomplete({ disabled: true });
If this solution doesnt work for you, you might have somewhere other problems. Make your code a little better, maybe something is causing some internal errors
change
$('[id$=POSTCODETextBox]').html("");
to
$('[id$=POSTCODETextBox]').val("");
try to work like this for postcodetextbox:
$('[id$=POSTCODETextBox]').autocomplete({
source: "somesource.aspx",
change: function(event, ui) {
$(this).autocomplete("destroy");
}
});
But this will disable the user from using it again...
You could also disable the textbox.
$('[id$=POSTCODETextBox]').attr("disabled", "disabled");
//when changing country, other postcodes will load
$('[id$=landenDropDown]').bind($.browser.msie ? 'propertychange' : 'change', function () {
//autocompletes removal
...
var LandCode = $('[id$=landenDropDown]').attr("value");
$('[id$=POSTCODETextBox]').autocomplete('destroy');
//autocomplete with postal codes for Belgium
if (LandCode == "BE") {
//autocomplete postcode from selected country
$('[id$=POSTCODETextBox]').autocomplete("PostcodeBE.aspx");
}
//autocomplete with postal codes for Holland
else if (LandCode == "NL") {
//autocomplete postcode from selected country
$('[id$=POSTCODETextBox]').autocomplete("thingXml.aspx");
}
else {
//test
getal += 1;
alert(getal);
}
精彩评论