title: Populating a form using <select> element and PHP
body: <p>I'm developing an addressing management system for our CMS that I've created, and I need to be able to take addresses stored in a SQL database and populate a form with the data when pulled from the database, but only after being selected with a <code>SELECT</code> element.</p>
  
  <p>I am able to read the data using PHP/WySQL, however, I'm relatively stumped as to how to use either Javascript (or Ajax?) to take the data, when picked via the <code>SELECT</code>, and move it to the respective input fields on the form.</p>
  
  <p>I realize that Javascript would require a function to fire with either the <code>onChange</code> or <code>onSelect</code> handler on the <code>SELECT</code> element (forgive my remedial understanding of Javascript/Ajax).</p>
  
  <p>Code resembles the following:</p>
  
  <pre><code>&lt;form action="action.php?step=2" method="post" name="frmAddress"&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;label for"presetAddress"&gt;Use a saved address&lt;/label&gt;
      &lt;select class="input" id="presetAddress"&gt;
        &lt;option value="none" selected="selected"&gt;Select...&lt;/option&gt;
  &lt;?php
    $sql = "SELECT * FROM table WHERE foo='$bar';
    $res = mysql_query($sql);
    while($row = mysql_fetch_assoc($res)) {
      if($row) {
        extract($row);
  ?&gt;
        &lt;option id="presetAddress" value="&lt;?php echo $id; ?&gt;"&gt;&lt;?php echo $address . " " . $city . ", " . $state . $x; ?&gt;&lt;/option&gt;
  &lt;?php
      }
    }
  ?&gt;
  &lt;/select&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>At this point, I have no idea where to start, but I'm not inclined to have someone just write it out entirely. I'm looking more to be pointed in the right direction, so I'm not having to keep coming back for things like this (I'd rather learn it now and be able to figure it out in the future).</p>