SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: running a PHP script javascript focusout event

  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    104
    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
    Grüße aus'm Pott
    SitePoint Award Recipient Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    2,716
    Mentioned
    46 Post(s)
    Tagged
    3 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
    How well do you know your JavaScript from your jQuery?
    Check out SitePoint's latest JavaScript challenge


    My blog

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
  •