Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>THis isn't complicated at all using ajax &amp; jquery!</p> <p>A quick dirty way is to do this</p> <pre><code>&lt;div id="firstName"&gt;&lt;/div&gt; &lt;script type='text/javascript'&gt; $('#lastNames').change(function() { $('#firstName').load('getfirstname.php?lastname=' + $(this).val()); }); &lt;/script&gt; </code></pre> <p>and for getfirstname.php page</p> <pre><code>$lastName = mysql_real_escape_string($_GET['lastname']); $sql="SELECT DISTINCT Name FROM firstName WHERE LastName ='$lastName'"; //using distinct to make sure there are no duplicates $result=mysql_query($sql); $options="&lt;select id='firstNames' style='margin-right:40px;'&gt;"; $options.="&lt;option value='blank'&gt;-- first name --&lt;/option&gt;" ; while ($row=mysql_fetch_array($result)) { $name=$row["Name"]; $options.="&lt;option value='$name'&gt;$name&lt;/option&gt;"; } $options.= "&lt;/SELECT&gt;"; echo $options; </code></pre> <p>Here is a very simple page that shows how to execute php code using ajax and jquery. </p> <pre><code>&lt;? if(!isset($_GET['value'])):?&gt; &lt;script src="jquery-1.7.1.js"&gt;&lt;/script&gt; &lt;select id="select" &gt; &lt;option value="1"&gt;1&lt;/option&gt; &lt;option value="2"&gt;2&lt;/option&gt; &lt;option value="3"&gt;3&lt;/options&gt; &lt;/select&gt; &lt;div id="phpoutput"&gt;&lt;/div&gt; &lt;script&gt; $('#select').change(function() { $('#phpoutput').load('?value=' + $(this).val()); }); &lt;/script&gt; &lt;?else: $val = $_GET['value']; echo "$val sent to server. $val*3 = " . $val *3; ?&gt; &lt;?endif;?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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