Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery results not being echoed to div on same page
    text
    copied!<p>been trying to figure out how to echo a query result to a textbox in a div. I have a form (see below) and it does place the result in a textbox as I want but is not echoing back to the div (which is called 'content'). I've updated the code for my HTML here after some edits:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="search" method="post" action="rating.php"&gt;Miles &lt;input name="miles" id="miles" type="text" /&gt; &lt;input name="search1" id="search1" class="btnButton" value="Search" type="submit" /&gt;&lt;/form&gt; &lt;div id="content"&gt;&lt;/div&gt; &lt;script type="text/javasript" src="jquery-1.9.0.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt;// &lt;![CDATA[ $(document).ready(function(){ //jquery click event $("#search").on("submit", function(e){ //disable default form submit postpage e.preventDefault(); //make ajax call to the search.php parsing the search textbox value as query string $.get("rating.php?miles="+$("#miles").val(), function(result){ //Result will be dumped in the div $("#content").html(result); }); }); }); // ]]&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The value of miles is now passed to rating.php where I want it to do a query and then format the result in a textbox format that is displayed in the div:</p> <pre><code>&lt;?php $hostname = 'somehost.com'; $username = 'ratetable'; $password = 'mypassword'; $miles = (int) $_POST['miles']; try { $db = new PDO("mysql:host=$hostname;dbname=ratetable", $username, $password); foreach($db-&gt;query("SELECT * FROM rates WHERE mileage&lt;={$miles} ORDER BY mileage DESC LIMIT 1") as $row) { $result= "&lt;input type='text' name='answer' value='" . $row['ratepermile'] . "'&gt;'"; echo $result; } } catch (PDOException $e) { echo $e-&gt;getMessage(); throw($e); } ?&gt; </code></pre> <p>The result is formatted the way I want, except that it is not being echoed back to the script and placed where the result should be. Is there a way I can use div tags or otherwise ensure it's going to a specific div? </p> <p>Thank you for looking.</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