I have a problem with a javascript function. It runs by itself when the page loads even if it`s set to run .onchange
I have a select that looks like this:
<select name="make_brand" id="make_brand" class="form_tag dispB width_full">
<option value="" selected disabled>Please select</option>
<option value="1">Audi</option>
<option value="2">BMW</option>
<option value="3">Mercedes-Benz</option>
</select>
And my js looks like this:
// defining select fields
var brand = document.getElementById("make_brand");
// get values
function getSelectedValue(element, show_mark){
return element.options[element.selectedIndex].value;
}
// on select change
brand.onchange = getSelectedValue(brand, true);
When I refresh the page, the function runs automatically and I don`t know why. Can anyone help me with this? I want the function to run on select change.