In the code below the function is executed in the onchange="timesquare(this)"
event of the select tag. How to replace this event with an onclick event on a <button onclick="???????????;">Converter</button>
button
function timesquare(s) {
var optionsTime = (s[s.selectedIndex].id);
var convert = document.getElementById('convert').value;
if (convert < 60) {
document.getElementById('resultTime').innerHTML = "Escolha um valor acima de 60";
return;
}
switch(optionsTime){
case "minutes":
document.getElementById('resultTime').innerHTML = 'Vc escolheu minutos';
break;
case "hours":
document.getElementById('resultTime').innerHTML = 'Vc escolheu Horas';
break;
default:
document.getElementById('resultTime').innerHTML = "no result";
break;
}
}
<input type="text" id="convert" placeholder="Insira os segundos">
<br>
<select onchange="timesquare(this)" id="optionsTime">
<option></option>
<option id="minutes">Minutos</option>
<option id="hours">Horas</option>
<option id="teste">Teste</option>
</select>
<br>
<span id="resultTime"></span>