Overwrite  values on Autocomplete jquery ...

Veljean
Veljean used Ask the Experts™
on
Hi

I have a DropDownlist of country states, when i select a state i want to populate a autocomplete editbox with jquery with all the posible results so the user can find the correct city in the current state. Till now i coded the following...

$(document).ready(function(){
   
//result is an array opf all the posible values...
 $("#AutoCompleteText").autocomplete(result, {
            matchContains: true,
            minChars: 0
      });

And it works nice but the problem is when i pick another different state, all the old locations remain in the memory (it seems that  jquery appends all the new items), i want to overwrite them!!

Can i reset all the values of the autocomplete editbox in jquery?  

  });
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
For each state change rebind the autocomplete field for new city list by calling

$("#AutoCompleteText").autocomplete(result,  {
            matchContains: true,
            minChars: 0
      });

where result is the list of cities.

Author

Commented:
hi shahzadfatehali

I did that before but the autocomplete field appends the new informations instead of rewrite them...

Commented:
Can you post your code here?

Author

Commented:
Sorry for the late answer ...

i dont have any relevant code , but here it is...
function ObtenerLocalidades()
{
 
 var ddlstate = document.getElementById("DDEstados");
 var state = ddlstate.selectedIndex;
  
  if (ddlstate.selectedIndex!=0)
  {
    PageMethods.GetAutoTextLocations(state,OnComplete,onError);          
  }

}

function OnComplete(result)
{

   
 $(document).ready(function(){
    

 $("#AutoCompleteText").autocomplete(result, {
		matchContains: true,
		autoFill: false,
		minChars: 0
	});



  });


 
 
}

function onError()
{

alert("Fail")
}

Open in new window

Commented:
I got it :

$('input#AutoCompleteText').flushCache();

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial