SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    running a PHP script with javascript after a text field 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.



    PHP Code:
    <!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 :  citystatecountry
        
    echo "<br>" $testArray['City'] . "    " $testArray['State'] . "    " $testArray['Country'];
           
    ?>
    </body>
    </html>
    Last edited by robin01; Dec 15, 2012 at 18:04. Reason: Title change

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,895
    Mentioned
    212 Post(s)
    Tagged
    12 Thread(s)
    Hi there,

    Quote Originally Posted by robin01 View Post
    What I like to do is run the location lookup script and echo the results before moving to the next step. To do this i needed to inject a little javascript.
    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.

    HTH


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •