选择下拉选项时如何触发javascript [英] how to trigger javascript when a dropdown option is selected

查看:44
本文介绍了选择下拉选项时如何触发javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对汽车品牌和型号的两个下拉框,当一个让选择我需要的所有车型在未来的框来显示.截至目前,使用以下代码,当单击下拉列表时,模型就会显示出来.

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. As of now using the following code the models show up when the dropdown is clicked.

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

但是,我需要从下拉菜单中选择一个选项而不是打开下拉菜单时触发javascript.

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

here also is the html - with some 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>

推荐答案

使用selectbox的 onchange 事件.

use the onchange event of selectbox.

这是演示

这篇关于选择下拉选项时如何触发javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆