You are on page 1of 1

<%--

Document : Calculadora01
Created on : 16/05/2019, 02:30:53 AM
Author : drivera
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script>
var num1, num2, res;

function calculo(x){

num1 = parseInt(formulario.n1.value);
num2 = parseInt(formulario.n2.value);
if(x.name=="B1")
res = num1 + num2;
else if (x.name=="B2")
res=num1-num2;
else if (x.name=="B3")
res=num1*num2;
else if (x.name=="B4")
if(num2==0)
res="No se puede dividir con 0";
else if(isNaN(num2))
res="Numero incorrecto";
else
res=num1/num2;

formulario.res.value=""+res;

</script>

</head>
<body>
<form name="formulario">

Numero 1: <input name="n1" type="text"><br><br>


Numero 2: <input name="n2" type="text">
<br><br>
<input name="B1" type="button" value="+" onclick="calculo(this)">
<input name="B2" type="button" value="-" onclick="calculo(this)">
<input name="B3" type="button" value="*" onclick="calculo(this)">
<input name="B4" type="button" value="/" onclick="calculo(this)">
<br><br>
Resultado: <input name="res" type="text">
</form>
</body>
</html>

You might also like