2
I’m new to programming, I’m having a problem with my code:
var micro = "Micro Inversores";
if (micro.equals(document.getElementById("tipo_unidade"))) {
var tipo1 = 1;
else
var tipo1 = 0.8;
}
<select id="tipo_unidade" name="tipo_unidade" onchange="MudaLabeL('compl_Preco_1',txt_qtd_1.value)" style="width:660px">
<option value="Micro Inversores">Micro Inversores</option>
<option value="Inversor Tradicional">Inversor Tradicional</option>
I have a field <option>
where the user selects an option, according to its selection, need the value of the variable tipo1
be it 0.8
or 1
.
I tried too:
var char micro = "Micro Inversores";
if (micro = p_classe) {
var tipo = 1;
else
var tipo = 0.8;
}
document.getElementById("p_classe").innerHTML = (classeundValue);
function atualizaclasse() {
var classeund = document.getElementById("tipo_unidade");
classeundValue = classeund.value;
}
If I remove the condition part if
and define, for example var tipo = 1;
, the code works perfectly. My problem is in setting this value of 0.8
or 1
for the type variable, according to the user’s selection.
I think you need to take the value of select with . value:
document.getElementById("tipo_unidade").value
– Sam