title: jQuery drop down to fill second drop down and text field
body: <p>I want to use jQuery to populate a second select box, and a text field. I have the second select box getting populated correctly when a selection is made in the first. I have not been able to get it to populate the text field though. </p>
  
  <p>The data is retrieved from a MySQL database. Below is the code that I have working for the first select box to make a selection in the second.</p>
  
  <p>My jQuery code:</p>
  
  <pre><code>&lt;script&gt;
  $(document).ready(function(){
    $("#shipment").change(function() {
      $("#vender").load("selection.php", $("#shipment"));
    }).trigger("change");
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Form Fields relevant to this:</p>
  
  <pre><code>&lt;html&gt;
  &lt;label for="shipments"&gt;Shipment: &lt;/label&gt;&lt;select id="shipment" name="shipment_id"&gt;
  &lt;?php if(isset($shipment_selection)) { echo $shipment_selection; } ?&gt; //echos options from db.
  &lt;/select&gt;
  &lt;label for="vender"&gt;Vender: &lt;/label&gt;&lt;select id="vender" name="vender_id"&gt;&lt;/select&gt;
  &lt;label for="cost"&gt;Cost: &lt;/label&gt;&gt;&lt;input type="text" id="cost" name="cost" value="" /&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>PHP Script that gets the data:</p>
  
  <pre><code>&lt;?php
  include('../scripts/db_config.php');
  
  if(isset($_POST['shipment_id'])) {
      if($_POST['shipment_id'] == 1) {
      $sql = 'SELECT id AS vender_id, name AS vender_name FROM venders'; //shows all venders, when shipment is none.
      }
  else {
  $sql = 'SELECT venders.id AS vender_id, venders.name AS vender_name, shipment.qty AS qty, shipment.cost AS cost FROM shipments INNER JOIN venders ON venders.id=shipments.vender_id WHERE shipments.id='.$_POST['shipment_id']; //Select vender associated with specific shipment.
  }
  $stmt = $db-&gt;query($sql);
  $data = array();
      while ($row = $stmt-&gt;fetch(PDO::FETCH_ASSOC)) {
      $data[] = $row;
      //echo '&lt;option value="'.$row['vender_id'].'"&gt;'.$row['vender_name'].'&lt;/option&gt;'; //populates second select box.
      }
  echo json_encode($data);
  }
  </code></pre>
  
  <p>I will secure the PHP code better after I get this working.</p>
  
  <p>Any suggestions on how to get a selection in the first select box to populate the second select box, and the text field would be great.</p>
  
  <p>Apologies if the formatting is off; I am blind, so I am not sure how it actually looks on screen.</p>