Steps to activate JavaScript upon selecting a dropdown menu item

My webpage has two dropdown boxes for car makes and models. I want all the models of a selected make to display in the next box. Currently, the models only show up when the dropdown is clicked using the code below.

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 would like the JavaScript to trigger when an option from the dropdown is actually selected, not just when it's opened.

Here is the HTML along 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){ 
                    echo "<option value='". $make ."'>". $make ."</option>";
                }
            ?>
            </select>
            <select id="model_drop" name="vmodels">
            <?php
            //no initial options
            ?>
            </select>       
            <input type="submit" value="Search Vehicle" />
        </div>
    </form>
</div>

Answer №2

Give this a shot:

<select name="Burger" size="5"
    onchange="anotherFunction()">
  <option value="B101">Cheeseburger</option>
  <option value="B102">Chicken Burger</option>
</select>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Prevent draggable functionality of jQuery UI on elements with a specific class

I have created a dynamic cart feature where users can drag and drop items into the cart. However, once an item is placed in the cart, it should no longer be draggable (though still visible but faded). I attempted to achieve this by using the following code ...

Optimizing Style Inclusion Order with Vue SFC, vue-loader, and webpack

My Vue/SFC/webpack/vue-loader application integrates bootstrap using 'import', with component styles directly included in the SFCs. However, vue-loader always places bootstrap after the component styles, preventing proper overwrite/cascade over b ...

What is the best way to create several sets of a numerical field and a checkbox? (checkbox will deactivate a specific number field)

I'm having an issue with generating multiple pairs of a number field and a checkbox. When I click the checkbox, it should disable the number field. However, only the first pair seems to be working. Can anyone lend a hand? Here's the code snippe ...

Tips for keeping a reading item in place while scrolling

To enhance the user experience, I would like to improve readability without affecting the scroll position. Question: Is there a way to fix the scrolling item at a specific position (item with the .active class)? I am looking to maintain a consistent read ...

Retrieving information from the backend using JavaScript

Utilizing devexpress JS Charts requires data to be in the format: [{ category: 'Oceania', value: 35 },{ category: 'Europe', value: 728 }] To achieve this format, I convert a DataTable to JSON in my backend code after running queries b ...

How can I resolve the issue of a lengthy link spanning two lines in Internet Explorer, while displaying correctly in other browsers on a Bootstrap navigation

Currently in the process of developing a responsive website with Bootstrap. The navigation buttons at the top are displaying correctly in Chrome, Safari, and Firefox, but in IE, the button labeled "Public Consultation" is wrapping onto two lines. I suspec ...

Exploring Vue.js: Navigating Through an Array of Images Nested Within Another Array

I am looking to showcase images stored in an array called "image" within another array named product. Essentially, if a product has an array of 3 images, I want to display all 3 images, and so on. Here is the code snippet: <template> <div c ...

Footer flickers while changing routes

There seems to be a glitch where the footer briefly flashes or collapses when switching routes, specifically if the page is scrolled down to the middle. If at the top of the page, the transition works smoothly. This issue becomes more apparent on high refr ...

Tips for creating a clickable popover within a window that remains open but can be closed with an outside click

Is there a way to ensure that my popover window remains clickable inside its own area without closing, but automatically closes when clicked outside of the window? This is the code I am currently using, which is triggered by a button click: if (response. ...

What is the method of displaying a querystring on my Angular view page without relying on a controller?

My experience lies in utilizing AngularJS 1. This excerpt showcases the stateprovider configuration present in my config.js file: JavaScript .state('projects', { abstract: true, url: "/projects", templateUrl: "views/common/master_pa ...

Is there a way to utilize loops/recursion in conjunction with promise-chains?

Consider a scenario in which you need to save paginated data retrieved from an API into a database. let db; let pageitems = 35 var offset = 0; dbConnect //connect to the database .then( fetch(apiLink+?offset=2) .then( res => res.json()) .the ...

What is the method to store anchor text in a Session variable?

I'm currently working on a project where I've linked multiple pdf files in the master page. When clicking the anchor, the page redirects to the specified location and displays the pdf in an iframe. Now, I want the text within the anchor tag to be ...

Using inline SVG within a Vue.js component

Recently, I embarked on a Vuejs project using @vue/cli version 3.0.0-beta.16. In my Home.vue single file component, I encountered an issue while trying to import and add inline SVG to the template. The crux of the problem lies in the fact that vue cli alr ...

Pick a unique identifier for the <a> element and add an event listener to it

I am using an Ajax function to generate a table. Within one of the columns, there is an anchor field with a specific id. I am looking to trigger an event when that anchor field is clicked. Here is my current approach: $( "#26" ).on('click', &ap ...

A guide to storing a JavaScript variable in a MySQL database using Express.js

Looking for some guidance on node js and expressjs framework. While developing a web application, I've encountered an issue with saving data into the database. Everything seems to be set up correctly, but the data stored in the variable (MyID) is not ...

Despite successfully passing props into V-for, the output does not display the props as expected

I've been attempting to accomplish a straightforward task, but for some reason, it's not working and I can't figure out why. Within the parent component, App.vue, I have the following: data() { return { servers: [ { ...

The divs are crashing into each other and moving at varying speeds

I have created a mini game inspired by diep.io on codepen, where you can upgrade your reload and shooting capabilities. However, I have encountered an issue where the bullets start moving at different speeds and end up overlapping each other after shooting ...

Tips for preventing multiple button clicks until the completion of the initial click event

I created a clock that tells the time every quarter as per the professor's request. However, there is an issue - when I click multiple times, the clock keeps telling the time repeatedly until the number of tellings matches the number of clicks. I thou ...

Using jQuery AJAX to send multiple variables through URL in PHP POST request

I am attempting to send this information to a PHP page in order to insert it into my database. $.ajax({ type:"post", url:"ajax/sale-your-car.php", data:"makes="+makes+"&model="+model+"&style="+style+"&price="+price+"&ExteriorCo ...

How to use javascript/html to differentiate between male and female names?

I've developed a random name generator code that is powered by both CSS and JavaScript. Currently, the code allows me to input any name - regardless of gender - press the generate button, and receive a randomly generated first and last name. However, ...