如何在select中向Onchange函数发送两个参数

时间:2015-09-18 09:49:14

标签: javascript ajax

我有以下代码

        <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()

2 个答案:

答案 0 :(得分:0)

你可以这样做:

<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;">

答案 1 :(得分:0)

我会按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>