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. 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);
    }
}

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

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>
1
  • 1
    can you post your HTML as well ? Commented Jul 29, 2013 at 10:30

2 Answers 2

6

use the onchange event of selectbox.

here is a demo

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

<select name="Pizza" size="5"
    onchange="myFunctionHere()">
  <option value="P101">Pizza Napoli</option>
  <option value="P102">Pizza Roma</option>
</select>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.