In the code below I get the option value
selected and used as a link (href)
, however I need it to be used as onClick
:
<form action="" method="POST" role="form">
<li>
<select id="bens" name="bens" class="form-control"
onChange="alterarComboVeiculo(this.value); ">
<option value='' selected>Selecione</option>
<option value='86764554'>867</option>
<option value='88564554'>885</option>
</optgroup>
</select>
</li>
</form>
<span id="alex">Selecione</span><a onclick="" href="" id="url"></a>
here where href=""
is replaced by empty space with option value
selected
<script type="text/javascript">
var select = document.getElementById('bens'),
output = document.getElementById('alex');
select.addEventListener('change', function() {
output.textContent = '' ;
var index = this.selectedIndex;
var prefix = "";
var suffix = "";
prefix = 'addOverlay_' + select.options[select.selectedIndex].text + "();";
var link = document.getElementById("url");
link.href = prefix;
link.innerHTML = "Alex";
});
</script>