Validar varios input text con for()
Publicado por Victor (2 intervenciones) el 05/06/2018 05:49:48
Hola.
Soy novato así que perdón por si incluyo burradas en el código. Quiero validar con un for tres entradas de input tipo text. Para ello he probado a hacerlo como en el código de abajo. En consola del navegador me aparece que el document.getElementbyId da null... si alguien me puede dar alguna pista de qué hago mal se agradece.
Soy novato así que perdón por si incluyo burradas en el código. Quiero validar con un for tres entradas de input tipo text. Para ello he probado a hacerlo como en el código de abajo. En consola del navegador me aparece que el document.getElementbyId da null... si alguien me puede dar alguna pista de qué hago mal se agradece.
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
35
36
37
<!DOCTYPE html>
<html>
<head>
<title>Testing 01</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action='' onsubmit="validar()">
<input type="text" id="number1" size="3" maxlength="3">
<input type="text" id="number2" size="3" maxlength="3">
<input type="text" id="number3" size="3" maxlength="3">
<input type="submit" id="boton" >
</form>
<script type="text/javascript">
function validar(){
for (i=1 ; i<=3 ; i++ ){
if ((isNaN(document.getElementById('number'+i).value)) )
{
document.write("El valor de la entrada"+ i +" no es un número");
}
else {
document.write("Valor de la entrada "+ i +" correcto");
}
}
}
</script>
</body>
</html>
Valora esta pregunta


0