2

I have two dropdown boxes for car makes and models, when a make is selected i need all its models to show in the next box. 截至目前使用以下代码,模型会在单击下拉列表时显示。

    window.onmousedown = function(e){
    this.id = e.target.id;
    if(this.id == "vehicle_makes"){
        var make = document.getElementById("vehicle_makes").value;
        ajaxCall(make);
    }
}

However i need the javascript to trigger when an option from the dropdown is selected rather than when the drop down is opened.

这里也是 html - 带有一些 php

<div class="vehicle-search-wrap">
    <form method="get" id="searchform" action="<?php bloginfo('url'); ?>">
        <div>
            <select id="vehicle_makes" name="s">
            <?php
                foreach($makes as $make){ //put all makes in dropdown
                    echo "<option value='". $make ."'>". $make ."</option>";
                }
            ?>
            </select>
            <select id="model_drop" name="vmodels">
            <?php
            //nothing to start
            ?>
            </select>       
            <input type="submit" value="Search Vehicle" />
        </div>
    </form>
</div>
4

2 回答 2

6

使用选择框的onchange事件。

这是一个演示

于 2013-07-29T10:31:53.260 回答
0

尝试这个:

<select name="Pizza" size="5"
    onchange="myFunctionHere()">
  <option value="P101">Pizza Napoli</option>
  <option value="P102">Pizza Roma</option>
</select>
于 2013-07-29T10:34:50.190 回答