
Object Undefined, problema con input y las funciones
Publicado por Moises (1 intervención) el 12/03/2022 21:14:20
Ayuda, el código debe mostrar la suma de dos numeros en el div, sería abajo del botón.
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
<!DOCTYPE html>
<html lang="en">
<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>Suma de dos numeros</title>
</head>
<body>
<input id="input1">Ingrese el numero 1</input>
<br>
<input id="input2">Ingrese el numero 2</input>
<br>
<input type="button" onclick="operacion()">Hacer operación</input>
<br>
<div id="output">
<script>
var n1,n2,n3,text;
n1 = parseInt(document.getElementById("input1"));
n2 = parseInt(document.getElementById("input2"));
function operacion(){
n3 = n1+n2;
text = toString(n3);
document.getElementById("output").innerHTML = text;
}
</script>
</div>
</body>
</html>
Valora esta pregunta


0