title: How do I populate textbox from a combobox selected
body: <p>i want a combobox which populates itself from a database column, when a user selects an option from the combobox it will populate textboxes, which are on the same page, with information related to the selection in the combobox.</p>
  
  <p>Below is the code I used to populate a textbox when I selected the select nama from the dropdown combobox. but it doesnt work, the textbox still blank.
  I have the drop down working and also it fills a JavaScript array using names but I just cannot work out how to use the array to show in the fields.</p>
  
  <p>i understand it will have to use javascript and Onchange function, can anyone point me in the right direction?</p>
  
  <p>cheers and thank in advance :)</p>
  
  <pre><code>&lt;script src="js/jquery.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
              var selected = new Array();
  
              &lt;?php
                  $query1 = "SELECT * FROM inventori";
                  $result1 = mysql_query($query1) or die(mysql_error());
  
                  // build javascript array
                  while($row1=mysql_fetch_array($result1)){ 
                      echo 'selected['.$row1['selectnama'].'] = new Array();';
                      echo 'selected['.$row1['selectnama'].']["NAMA_BAHAN_BAKU"] = "'.$row1['NAMA_BAHAN_BAKU'].'";';
                      echo 'selected['.$row1['selectnama'].']["SATUAN"] = "'.$row1['SATUAN'].'";';
                  }
              ?&gt;
  
              function showname() {
                  var selectnama = document.formInventori.selectnama.value;
                  document.formInventori.SATUAN.value = selected[selectnama]["SATUAN"];
              }
  
              window.onload=function() {
                  showname();
              } 
  
          &lt;/script&gt;
  
      &lt;form role="form" action="" method="post" name="formInventori"&gt;
            &lt;div class="form-group"&gt;
                 &lt;label for="NAMA_BAHAN_BAKU"&gt;Nama Bahan Baku&lt;/label&gt;
                 &lt;select class="form-control" name="selectnama" onchange="showname()"&gt;
                 &lt;option value=""&gt;Pilih Nama Bahan Baku&lt;/option&gt;
                 &lt;?php
                     $query1 = "SELECT * FROM inventori";
                     $result1 = mysql_query($query1) or die(mysql_error());
                     // build javascript array
                     while($row1=mysql_fetch_array($result1)){ 
                          echo '&lt;option value="'.$row1['ID_BAHAN_BAKU'].'"&gt;'.$row1['NAMA_BAHAN_BAKU'].'&lt;/option&gt;';     }
                 ?&gt;
                 &lt;/select&gt;
            &lt;/div&gt;
            &lt;div class="form-group"&gt;
                 &lt;label for="SATUAN"&gt;Satuan Barang&lt;/label&gt;
                 &lt;input type="text" class="form-control" readonly="" id="SATUAN" name="SATUAN" value=""&gt;
            &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>