Q:

Get Value selected combobox dynamic data in javascript

i have a combobox that list a dynamic data from database, i use javascript, and it's works. but the problem is how to get the selected value ? i want to get value of "pilih rayon". this is the picture and code.

<script type="text/javascript">
    function showcabang(){
    <?php
    require ('config.php');
    $query = "SELECT distinct org_id FROM gis";
    $cabang = pg_query($query);

    while ($data = pg_fetch_array($cabang))
     {
       $idcabang = $data['org_id'];

       // membuat IF untuk masing-masing propinsi
       echo "if (document.list.cabang.value == \"".$idcabang."\")";
       echo "{";

       // membuat option kabupaten untuk masing-masing propinsi
       $query2 = "SELECT distinct cp_rayon_name FROM gis WHERE org_id = $idcabang ORDER BY cp_rayon_name";
       $hasil = pg_query($query2);
       $content = "document.getElementById('rayon').innerHTML = \"<select name='rayon'>";
       while ($data2 = pg_fetch_array($hasil))
       {
           $content .= "<option value='".$data2['cp_rayon_code']."'>".$data2['cp_rayon_name']."</option>";
       }
       $content .= "</select>\";";
       echo $content;
       echo "}\n";
     }

    ?>

    }
    </script> 

<html>
    <form name="list"  method="post"  action="json.php">
    <table>
    <tr><td>Pilih ID Cabang</td><td>:</td>
          <td>
              <select name="cabang" onchange="showcabang()">
              <option>Silakan Pilih</option>
              <option>------------------------</option>
              <?php
                     // query untuk menampilkan propinsi
                     $query = "SELECT distinct org_id FROM gis ORDER BY org_id";
                     $hasil = pg_query($query);
                     while ($data = pg_fetch_array($hasil))
                     {
                        echo "<option value='".$data['org_id']."'>".$data['org_id']."             </option>";
                     }
              ?>
              </select>
          </td>
    </tr>
    <tr><td>Pilih rayon</td><td>:</td>
          <td>

          <select name="namarayon" id="rayon"></select>
          </td>
    </tr>
    <tr><td><input type="submit" name="submit" value="Submit" /></td></tr>
    </table>
    </form>
</html>

A:

in your json.php file when the form has been submmited you can consume your data by using $_POST['cabang'] and $_POST['namarayon'].

