Running a PHP script javascript focusout event


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>

  <script src=""></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"); });

      <h2>FocusOut Event Out</h2>
       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'];

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()]( method. This should do what you want.