0
Good afternoon, you guys, I am trying to make you calculate again using other types of field, such as checkbox and list with some conditions, in some tutorials I tried to understand how it works, but I could not make generate the result, if you can take a look and guided thank.
<script type="text/javascript">
function calcular(oper){
var tributacao = document.mensalidade.tributacao.value;
var qt_func = document.mensalidade.qt_func.value;
var fat_mes = document.mensalidade.fat_mes.value;
var tipo_emp = document.mensalidade.tipo_emp.value;
var qt_func2 = qt_func * 20;
alert (qt_func2);
var soma = parseInt(qt_func2) + parseFloat(tributacao) + parseInt(prestacao) + parseInt(industrial) + parseInt(comercial) ;
if (fat_mes <= 25000){
var res = parseInt(0) + parseFloat(soma);
} else (fat_mes > 25000 && fat_mes <= 30000){
var res = parseFloat(soma) + 115;
} else (fat_mes > 30000 && fat_mes <= 40000){
var res = parseFloat(soma) + 150;
} else (fat_mes > 40000 && fat_mes <= 50000){
var res = parseFloat(soma) + 190;
} else (fat_mes > 50000 && fat_mes <= 60000){
var res = parseFloat(soma) + 230;
} else (fat_mes > 60000 && fat_mes <= 70000){
var res = parseFloat(soma) + 270;
} else (fat_mes > 70000 && fat_mes <= 80000){
var res = parseFloat(soma) + 310;
} else (fat_mes > 80000 && fat_mes <= 90000){
var res = parseFloat(soma) + 350;
} else (fat_mes > 90000 && fat_mes <= 100000){
var res = parseFloat(soma) + 390;
} else (fat_mes > 100000 && fat_mes <= 110000){
var res = parseFloat(soma) + 430;
} else (fat_mes > 110000 && fat_mes <= 120000){
var res = parseFloat(soma) + 470;
} else (fat_mes > 120000){
var res = (parseFloat(soma) * 0.40) / 100
}
document.mensalidade.res.value = res;
}
</script>
<form name="mensalidade" method="post" action="">
<label>Tributação</label><br>
<select id="tributacao" name="tributacao" class="form-control input">
<option value="0">Escolha</option>
<option value="49.90">MEI</option>
<option value="219">Simples Nacional</option>
<option value="319">Lucro Presumido</option>
<option value="2650">Lucro Real</option>
</select><br><br>
<label>Quantidade de Funcionarios</label><br>
<input type="text" name="qt_func" id="qt_func"><br><br>
<label>Faturamento mes</label><br>
<input type="text" name="fat_mes" id="fat_mes"><br><br>
<label>Selecione os Tipos</label><br>
<input type="checkbox" name="tipo_emp" id="tipo_emp" value="30">Serviços
<input type="checkbox" name="tipo_emp" id="tipo_emp" value="150">Industrial
<input type="checkbox" name="tipo_emp" id="tipo_emp" value="80">Comercial<br><br>
<input type="text" name="res" id="res"><br><br>
<input type="button" value="Calcular" onClick="calcular(document.mensalidade.fat_mes.value)"/>
</form>
I don’t understand, what should happen? Please explain better
– Guilherme Nascimento
it should multiply qt_func by 20 and add the rest of the fields and go through the variable, add the value inside, but it is not showing in the res field...
– Vinicius Nakamura
All the
else
are wrong, should beelse if
. The latter could be shortened to} else {
(omitting the comparison condition, if justified)– Luis Henrique
It is well explained, with the pardon of the word, I suppose that the "res" you refer is the element
<input id="res">
. The way you write people have to work harder to understand what you wrote and what you want than to understand where your code fails, that is to say people spend a lot of time trying to understand you instead of spending time trying to find the problem of your code. Please understand as a constructive criticism.– Guilherme Nascimento
@Luishenrique well noticed, I had not even looked at the code because the question itself was hard to understand, good +1
– Guilherme Nascimento
@Luishenrique actually the last
else
this wrong too. Everyone is wrong.– Guilherme Nascimento
In fact the question is very confused, I did not understand her either, but just to hit the code gave to realize the error (not that it is only this). I corrected the last remark
else
.– Luis Henrique
Sorry, but I’m new to javascript and I’m trying to explain the way I see, I know it’s something simple, but I’ve been killing myself for about 4 days, hunting and trying to do the code.
– Vinicius Nakamura
@Viniciusnakamura no one is complaining about your code or your understanding of js, I’m criticizing the way you wrote it yourself, but now it’s a little clearer the question after talking, however it’s a typo (off-topic), I’ll even answer, I hope it helps.
– Guilherme Nascimento
I am only apologizing, relax ;) because I am trying to learn javascript and ta being a fight. rs
– Vinicius Nakamura