1

我有一个组合框,它列出了数据库中的动态数据,我使用 javascript,它可以工作。但问题是如何获得选定的值?我想获得“pilih rayon”的价值。这是图片和代码。

这是图片

<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>
4

1 回答 1

0

提交表单后,在您的 json.php 文件中,您可以使用$_POST['cabang'] and $_POST['namarayon'].

于 2013-07-03T05:10:31.070 回答