php - Ajax fill in city automatically -


i have html form, , when fill in zipcode, want city field automatically updated city belongs zipcode.

here's form:

<form method="post" action="">     <input type="text" name="zipcode" id="zipcode">     <input type="text" name="city" id="city"> </form> 

here ajax:

$('#zipcode').keyup(function () {     var el = $(this);     if (el.val().length == 4) {         $.ajax({             url: 'get_city.php',             cache: false,             type: "get",             data: "zipcode=" + el.val(),             success: function (data) {                 $('#city').val(data);             }         })     } }); 

and here php

$db = mysql_connect('localhost', 'root', ''); mysql_select_db('testbox_new', $db);  $sql = 'select * cities zipcode = "'.$_get['zipcode'].'"'; $result = mysql_query($sql); while ($row = mysql_fetch_array($sql)) {     return $row['city_name']; } 

anyone knows why isn't working?

thx :)

you returning value find instead of echoing it.

try

echo $row['city_name']; 

instead of

return $row['city_name']; 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -