Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have one issue at least in the code, which is that in getChiefJudgeContactDetails() you're mixing javascript with php. Mixing the two works fine if it's the first time you output a page and the code is on a PHP page. But if you're expecting the javascript to run PHP code every time a change event is triggered from the auto-complete, then that won't work.</p> <p>Use the select event as others have stated, inside that, make a ajax request to a similar end point as your autocomplete but send it the value of your option (e.g. the ID value 2). Then use SQL in a PHP script to fetch the row for that id and return it as a json object. Parse the result and update UI in the jquery ajax call result handler.</p> <h2>update:</h2> <p>Change your autocomplete to look like this</p> <pre><code>&lt;script&gt; jQuery(document).ready(function($) { $('#inputChiefJudge').autocomplete({ source:'lookups/shows-sj-searchforjudge.php', select: function (event, ui) { $.ajax({ type: POST, url: 'lookups/shows-sj-findtel.php', data: {id:id}, success: function(data) { details = $.parseJSON(data); $('#inputChiefJudge').text("hello"); $('#chiefjudgetel').text(details); }, }); }, minLength:2}); }); &lt;/script&gt; </code></pre> <p>Instead of using the <strong>change</strong> option of the autocomplete, use <strong>select</strong> (as stated by other answers to your question). Also, instead of using a string ("id="+id) as your data, use a js object ({id:id}). jquery will handle serializing it correctly before sending to the server, the result being that it actually shows up as a post variable in your php script.</p> <p>Also, as more of a side note, I would suggest looking into using the PDO driver (<a href="http://www.php.net/manual/en/pdo.prepare.php" rel="nofollow">http://www.php.net/manual/en/pdo.prepare.php</a>) to access your database instead of using the mysql_* commands. It's object oriented and also automatically provides safety features that are not available in the old commands, such as prevention of SQL injection attacks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload