1
Next: I have to enter the name and price and status data, depending on the state it calculates the icms. I wanted to make sure that depending on the OPTION I select it calculated automatically, with the if’s and Else’s. but I don’t know if I’m referencing the option id right for javascript. Can you help me? It’s a little urgent
ICMS
<meta charset="utf-8">
<script type="text/javascript">
var nome;
var preco;
var estado;
var icms=0;
function calculo(){
nome = document.calculo.nome.value;
preco = parseFloat(document.calculo.preco.value);
estado = document.getElementById("estado").id;
if (estado.id="sp") {
icms = preco * 0.019;
}else{
if (estado.id="rj") {
icms = preco * 0.012;
}else{
if (estado.id="sc") {
icms = preco * 0.09;
}else{
if (estado.id="se") {
icms = preco * 0.08;
}else{
if (estado.id="mg") {
icms = preco * 0.1;
}
}
}
}
}
alert('ICMS: ' + icms.toString());
}
</script>
<form name="calculo">
<label for="nome" title="Nome do produto">Digite o nome do produto</label>
<br>
<input type="text" id="nome">
<br><br>
<label for="preco" title="Preço">Digite o preço do produto</label>
<br>
<input type="text" id="preco">
<br><br>
<label>Estado</label>
<select id="estado">
<option id="sp"> SP
<option id="mg"> MG
<option id="rj"> RJ
<option id="sc"> SC
<option id="se"> SE
</select>
<br><br>
<input type="button" value="Calcular" onclick="calculo()">
<input type="reset" value="Limpar">
</form>
ifs are all wrong. You have to use
==
to compare values, not just one=
.– Sam