Running a PHP script javascript focusout event

Hello,

I have a text field in my form for a location look up. user enters the zip code and the class returns the city, state, and country and the location information is returned to an array.

What I like to do is run the location looup script and echo the results before moving to the next step. To do this i needed to inject a little javascript.

Im not too familiar with JavaScript. I found a small script that works some whate but im not sure how to intergrate the javascript and php script in this case.

Any help you can provide me would be greatly appreciated.


<!DOCTYPE html>
<html>
<head>

  <script src="http://code.jquery.com/jquery-latest.js"></script>
  <script language="javascript" type="text/javascript">
        $(document).ready(function ()
        {    $("#zipcode").focusout(function (event)
	{       alert("Zip code field must not be empty... how do i run a PHP script here to pull informaiton from the array"); });
         });
</script>

</head>
<body>
      <h2>FocusOut Event Out</h2>
       <br>
       Test field 1: <input type="text" id="test1"  /> <br /><br />	
        Enter zip code: <input type="text" id="zipcode"  /> <br /><br />
       <?php \\\\PHP script to display :  city, state, country
	echo "<br>" . $testArray['City'] . "    " . $testArray['State'] . "    " . $testArray['Country'];
       ?>
</body>
</html>

Hi there,

What you could to do is use Ajax to send your data to the PHP script which will return the results you need on the fly.
You can then use these results to populate your location lookup.

Look into jQuery’s [post()](http://api.jquery.com/jQuery.post/) method. This should do what you want.

HTH