problema al sumar dos variables en dos input
Publicado por diego (12 intervenciones) el 01/02/2017 13:15:08
Hola de nuevo veries estoy hacinedo un ejercicio de introducir dos valores, a través de inputs yque me la suma.
Pero de momento me está dando error (NaN)
Os pasó los archivos por si me podeis ayudar.
Gracias como siempre
documento html
documento jq
Pero de momento me está dando error (NaN)
Os pasó los archivos por si me podeis ayudar.
Gracias como siempre
documento 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Suma</title>
<script src="js/jquery.js"></script>
<script src="js/suma.js"></script>
</head>
<body>
<div id="suma">
<input type="text" name="text" id="valor1" maxlength="10">
<label for="text"> Introduce primer num</label><br>
<input type="text" name="text" id="valor2" maxlength="10">
<label for="text"> Introduce segundo num</label><br>
<div class='text'>Total</div><div class='input'><input type='text' name='total' id='total' disabled='disabled'></div>
<p id="yo"></p>
<p id="po"></p>
<p id="sum"></p>
</div>
</body>
</html>
documento jq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$(document).ready(inicio);
function inicio(){
$("#suma input").keyup(calcular);
}
function calcular(){
var valor1=('#valor1').value;
var valor2=('#valor2').value;
valor1=parseInt(valor1);
valor1=parseInt(valor2);
$("#total").val(valor1+valor2);
$("#yo").text(valor1);
}
- ejer_suma.rar(29,5 KB)
Valora esta pregunta


0