Link to home
Start Free TrialLog in
Avatar of Veljean
Veljean

asked on

Overwrite values on Autocomplete jquery ...

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?  

  });
Avatar of Shahzad Fateh Ali
Shahzad Fateh Ali
Flag of Pakistan image

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.
Avatar of Veljean
Veljean

ASKER

hi shahzadfatehali

I did that before but the autocomplete field appends the new informations instead of rewrite them...
Can you post your code here?
Avatar of Veljean

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of Veljean
Veljean

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial