-
Notifications
You must be signed in to change notification settings - Fork 0
/
pag15.html
34 lines (30 loc) · 962 Bytes
/
pag15.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE-edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
function calcular()
{
var v1 = parseInt(document.getElementById('n1').value);
var v2 = parseInt(document.getElementById('n2').value);
document.getElementById('resultado').innerHTML = (v1+v2);
try {
if (isNaN(v1) || isNaN(v2)) throw "valor invalido";
} catch (error) {
alert(error);
}
}
</script>
<form action="" method="post">
Valor 1: <input type="text" ID="n1" ><br><br>
Valor 2: <input type="text" ID="n2" onblur="calcular()"><br>
<input type="button" onclick="calcular()" value="Soma">
</form>
<h1 id="resultado"></h1>
</body>
</html>