I have a function that creates a dropdown list from an array
function populateDropdown(){
var select = document.getElementById("dropdownList");
var array = ["1", "2", "3"];
for(var i =0; i < array.length; i++)
{
var opt = array[i]
var ele = document.createElement("option");
ele.textContent = opt;
ele.value = opt;
select.appendChild(ele);
}
}
With the following HTML:
<select id = "dropdownList">
<option> Choose a vendor </option>
</select>
I have a javascript function that will change the web page's functionality based on which dropdown item is being used. The new_vendor should be the name of the dropdown item, in this case either "1", "2", or "3".
function changeVendor(new_vendor)
How would I add something like an onClick to the dynamic dropdown and call the changeVendor function with that item name?