-1
What was the mistake? I was doing a calculator project where I used "onclick" and each button gave a number from 1 to 4. In the method "Total(num1, num2, X)" I used parameter-by-position, the result should go back to INPUT TYPE "TEXT", but there is no return of values. I don’t know what my mistake was.
function calc(X)
{
var num1 = document.getElementById("nmr1").value;
var num2 = document.getElementByid("nmr2").value;
if (isNaN(num1) || (num1==""))
{
alert("Você sabe ler? Digite um n°");
document.getElementById("nmr1").value = "";
document.getElementById("nmr1").focus();
}
else if(isNaN(num2) || (num2==""))
{
window.alert("Você sabe ler? Digite um n°");
document.getElementById("nmr2").value = "";
}
else
{
num1 = eval(num1);
num2 = eval(num2);
document.getElementById("resu").value = Total(num1, num2, X);
}
}
function Total(num1, num2, X)
{
var resultado;
if(X==1)
resultado = num1 + num2;
else if(X==2)
resultado = num1 - num2;
else if(X==3)
resultado = num1 * num2;
else if(X==0)
{
window.alert("Não existe divisão por 0");
resultado = "Não há valor válido";
document.getElementById("resu").size=14;
}
else
resultado = num1/num2;
return resultado;
}
function aumenta(X)
{
if(X==1)
document.getElementById("nmr1").size=8;
else
document.getElementById("nmr2").size=8;
}
function diminui(X)
{
if(X==1)
document.getElementById("nmr1").size=2;
else
document.getElementById("nmr2").size=2;
}
function limpar()
{
document.getElementById("nmr1").focus();
}
</SCRIPT>
</HEAD>
<BODY>
<blockquote><blockquote><blockquote><blockquote><blockquote><blockquote><blockquote><blockquote></blockquote>
<H5>
<FORM>
<H3><CENTER>Calculadora Doida</CENTER></H3>
<HR/>
INSIRA O 1° VALOR
<INPUT Type = "text" id = "nmr1" onFocus = "aumenta(1)" onBlur = "diminui(1)"/> <br/><br/>
INSIRA O 2° VALOR
<INPUT Type = "text" id = "nmr2" onFocus = "aumenta(2)" onBlur = "diminui(2)"/> <br/><br/>
O RESULTADO É
<INPUT Type = "text" id = "resu" onChange = "aumenta(3)" disabled/> <br/><br/><br/>
<!--value: o valor que vai escrito no item/objeto-->
<INPUT Type = "button" value = "+" onClick = "calc(1)" class = "pressiona"/>
<INPUT Type = "button" value = "-" onClick = "calc(2)" class = "pressiona"/>
<INPUT Type = "button" value = "x" onClick = "calc(3)" class = "pressiona"/>
<INPUT Type = "button" value = ":" onClick = "calc(4)" class = "pressiona"/>
<INPUT Type = "reset" value = "C" onClick = "limpar()" class = "pressiona"/>
<BR/><BR/><BR/>
<HR/>
<br/><br/><br/>
</FORM>
</H5>
</blockquote></blockquote></blockquote></blockquote></blockquote></blockquote> </blockquote></blockquote>
</BODY>
thank you very much, friend. the problem was obvious and I did not notice it. Thank you very much, have a good day
– oiniciante
I added a few tips to the answer =)
– Isaac Bruno
thanks again, I will use.
– oiniciante