0
i would like to know how to assign values to the selects of my code, for example if person select "from R$ 25,000/month to R$ 50,000/month" a value is generated in the Javascript code equivalent to 50, because I want to take this value to make a calculation at the end.
An example of something similar to what I want to do is shown in GIF, where varying the value of <input>
the total value is also changed.
My code is currently this:
HTML
var faturamento_anual = document.getElementById('faturamento')
var faturamento_selecionado = ""
if (faturamento_anual[1].checked) {
faturamento_selecionado = '50'
} else if (faturamento_anual[2].checked) {
faturamento_selecionado = '150'
}
<select name="faturamento" id="faturamento">
<option value="cinco_mil"><li>Até R$ 5.000/mês</li></option>
<option value="dez_mil">de R$ 5.000/mês até R$ 10.000/mês</option>
<option value="vinte_mil">de R$ 10.000/mês até R$ 25.000/mês</option>
<option value="cinquenta_mil">de R$ 25.000/mês até R$ 50.000/mês</option>
<option value="cem_mil">de R$ 50.000/mês até R$ 100.000/mês</option>
<option value="mill_mil">mais de R$ 100.000/mês</option>
</select>
And in Javascript I tried but gave error in every calculation system.
Puts the javascript you’re trying for...
– MagicHat
First, welcome. Look, you will have to hold a change event in your select. And you can also assign the values to the values of the respective options. When you perform the event change, then you can take the selected value by making a Document.getElementById and taking the value of the select and assign it to a variable, for example.
– Gato de Schrödinger
The attribute that indicates whether an option has been selected is
selected
naychecked
.– user142154