We have a radio button with three different values and a select box with several different values, how could I multiply the radiobutton checked with the value of the select box and put the result in a field?
Radio button code:
<input required="required" value="1" name="diarias" id="diaria1" type="radio"><label
for="diaria">Uma diaria</label>
<input required="required" value="2" name="diarias" id="diaria2" type="radio"><label
for="diaria">Duas diarias</label>
<input required="required" value="3" name="diarias" id="diaria3" type="radio"><label
for="diaria">Três diarias</label><br>
Select box code:
<select name="cidade" id="cidade" onclick="calcularopcoes();">
<option name="nenhum" value=""> Escolher </option>
<option name="saopaulo" value="244.00"> São Paulo </option>
<option name="fortaleza" value="412.80"> Fortaleza </option>
<option name="Blumenau" value="412.80"> Blumenau </option>
<option name="riopreto" value="400.90"> Rio Preto </option>
</select>
And the Javascript I tried to do but it did not work.
'<script type="text/javascript">
function calcularopcoes(){if(document.getElementById("ajudacusto").value.length < 0){
alert('Por favor, deve se escolher uma opção');
document.getElementById("ajudacusto").focus();
return false
}
if(document.getElementByName("diarias").value.length < 0){
alert('Por favor, deve se escolher uma opção');
document.getElementByName("diarias").focus();
return false
}
// vamos obter o elemento select
var elem = document.getElementById("cidade");
var elem2 = document.getElementByName("diarias");
var selecionou = elem.options[elem.options.selectedIndex]*1 * elem2.options[elem2.options.selectedIndex]*1;
// passa opção selecionada para campo
document.getElementById("ajudacusto").value = selecionou.value;
}
</script>'
What better way can we do? That the user click on the daily and choose the city he / she calculates of multiplication automatically and deposits in the field?