Click here to Skip to main content
15,908,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have used automplete by using php code.I need to show my zip code by country wise. But my oldcountry zip code is showing.while i changing the first country to other country.plz help me. :( :( :( :( :( :(
JavaScript
$(function() {
           var pageUrl = document.getElementById('pageurl').value;
           $('#zip_business').autocomplete({
               serviceUrl: pageUrl + "businesses/ajax.php",
               extraParams: {
                   country: function() {
                       return $('#country').val();
                   }
               }
           });
       });



ajax.php

PHP
$sqlData = mysql_query("SELECT * FROM zipcodes WHERE zip LIKE '".$_REQUEST['q']."%' AND country='".$_REQUEST['country']."'");
$values = '';
while ($getData = mysql_fetch_array($sqlData)) {
      $values.=$getData['zip'] . "," . $getData['full_state'] . "," . $getData['city'] . "|" . $getData['zip'] . "\n";
}
echo $values;
Posted
Updated 16-Aug-15 4:19am
v3
Comments
Please debug and check what is the value of country inside the autocomplete code.
Sradhanjali Behera 26-Aug-15 9:11am    
ok thank you.I found solution to this problem.
xszaboj 16-Aug-15 16:03pm    
I think that you need to refresh your autocomplete on country change.
Sradhanjali Behera 26-Aug-15 9:12am    
yes ,its not refreshing properly.I made same chnages to it.Thank you .

1 solution

Okay I got it. You need to handle the onchange event of the country dropdownlist.

Inside the onchange event, get the value of country and call the server side method to get all the zip codes for the country selected.
 
Share this answer
 
Comments
Sradhanjali Behera 26-Aug-15 9:12am    
Thank you :)
Welcome. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900