簡體   English   中英

如何在select中將兩個參數發送到Onchange函數

[英]How to send two parameters to Onchange function in select

我有以下代碼

        <option value="">Select State</option>
                        <?php
         while($row=mysql_fetch_array($select))
         {
          echo "<option value=".$row['state_id'].">".$row['state']."     </option>";
         }
         ?>
                        </select>
                        </label>




                        <label style="margin-left:20px; width:200px; float:left; padding-top:6px;">

                        <select name="city" id="city" onChange="getArea('indexcontroller/indexmodules/findarea.php?city='+this.value)" style="width:220px;margin-left:3px;height:39px;margin-top:6px;">
                        <option value="">Select City/Town</option>
                        </select>

如何將狀態中選擇的值發送到 getArea()

你可以這樣做:

<select name="city" id="city" onChange="getArea('indexcontroller/indexmodules/findarea.php?city='+$('#StatedropDownId').val();)" style="width:220px;margin-left:3px;height:39px;margin-top:6px;">

我會通過 id 選擇元素並獲取它的值

<select id="stateSelect">
    <option></option>
    <option></option>
    <option></option>
    <option></option>
    ...
</select>

<select id="citySelect" onchange="getArea('indexcontroller/indexmodules/findarea.php?state=' + document.getElementById('stateSelect').value + '&city='+this.value)">
    <option></option>
    <option></option>
    <option></option>
    <option></option>
    ...
</select>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM