// Get first dropdown
let firstDropdown = document.getElementById('first_dropdown');
// When a value is selected in the first dropdown
firstDropdown.addEventListener('change', function() {
// Get value chosen by the user
let firstDropdownValue = firstDropdown.options[firstDropdown.selectedIndex].value;
if (firstDropdownValue == 'ab') {
// Add the values in the second dropdown based on the value selected in the first dropdown
let secondDropdown = document.getElementById('second_dropdown');
let option_1 = document.createElement('option');
option_1.value = 'a';
option_1.innerHTML = 'a';
secondDropdown.appendChild(option_1);
let option_2 = document.createElement('option');
option_2.value = 'b';
option_2.innerHTML = 'b';
secondDropdown.appendChild(option_2);
}
});
// Get second dropdown
let secondDropdown = document.getElementById('second_dropdown');
// When a value is selected in the first dropdown
secondDropdown.addEventListener('change', function() {
// Get value chosen by the user
let secondDropdownValue = secondDropdown.options[secondDropdown.selectedIndex].value;
if (secondDropdownValue == 'a') {
// Add the values in the second dropdown based on the value selected in the first dropdown
let thirdDropdown = document.getElementById('third_dropdown');
let option_1 = document.createElement('option');
option_1.value = 'aa';
option_1.innerHTML = 'aa';
thirdDropdown.appendChild(option_1);
let option_2 = document.createElement('option');
option_2.value = 'aaa';
option_2.innerHTML = 'aaa';
thirdDropdown.appendChild(option_2);
}
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.