0
I am working on a payroll and the function that calculates the IR (income tax) is with some mistake that I honestly am not able to find at all. If anyone can help me.
function desconto_ir()
{var salario = document.getElementById("salario_bruto").value;
var inss = document.getElementById("valor_calculado_11").value;
var esposa = document.getElementById("casado").value;
var dp1 = document.getElementById("filhos").value;
var dp2 = document.getElementById("dp_22_24").value;
var dependentes = eval(esposa + dp1 + dp2);
var base_de_calculo = (parseFloat(salario - inss - (179.71 * dependentes))).toFixed(2);
if (base_de_calculo <= 1787.77)
{document.getElementById("valor_ir").innerHTML = base_de_calculo;}
else if (base_de_calculo >= 1787.78 && <= 2679.29)
{document.getElementById("valor_ir").innerHTML = (parseFloat((base_de_calculo * 0.075) - 134.08)).toFixed(2);}
else if (base_de_calculo >= 2679.30 && <= 3572.43)
{document.getElementById("valor_ir").innerHTML = (parseFloat((base_de_calculo * 0.15) - 335.03)).toFixed(2);}
else if (base_de_calculo >= 3572.44 && <= 4463.81)
{document.getElementById("valor_ir").innerHTML = (parseFloat((base_de_calculo * 0.225) - 602.96)).toFixed(2);}
else
{document.getElementById("valor_ir").innerHTML = (parseFloat((base_de_calculo * 0.275) - 826.15)).toFixed(2);}}
What error are you getting? Provide more details about the problem. Use the code in the question instead of a print.
– celsomtrindade
Actually the form does not load anymore since I did this function. If I delete it, it returns to function normally. I’ve reviewed all the syntax, the {} and () are closed correctly, the Ids are right... I really can’t find.
– Silas Renan
But what is the error? Calculation error? Data insertion error? When is this function called? Can you debug to see if what you expect is coming? It is this information that is important. Try to improve your issue by providing more information on the issue as detailed as possible.
– celsomtrindade
The function is called by a button (onclick). As the form does not load anymore, I do not know if the error is of calculation or insertion, I’m trying to exchange the expressions for others to see if it works... I’m a beginner programmer yet.
– Silas Renan
I put the code here but unfortunately not here Indenta, it was all together.
– Silas Renan
To format the text: http://answall.com/help/formatting
– celsomtrindade
Good night Silas, what mistake appears on the console?
– Guilherme Nascimento
Thanks for formatting for me :) So there is no error. The form page no longer loads. If I delete the function, it loads back normally.
– Silas Renan
Sorry I know the question will seem strange, please answer, you know what the console is?
– Guilherme Nascimento
I tried to test and in my console appeared error,
Uncaught SyntaxError: Unexpected token <=
, it is very important you inform this kind of thing when asking.– Guilherme Nascimento