JavaScript - me ayudan? quiero que según el numero del input se haga una acción diferrnte

 
Vista:
sin imagen de perfil

me ayudan? quiero que según el numero del input se haga una acción diferrnte

Publicado por anonymous (50 intervenciones) el 05/06/2016 11:45:05
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
<!DOCTYPE html>
<html>
<head>
<script>
function seleccion(){
var n1=document.calc.n1.value;
switch(n1){
case 0:
alert("holA");
break;
case 1:
alert("2");
break;
case 2:
alert("3");
break;
case 3:
alert("4");
break;
}}
</script>
<title>Page Title</title>
</head>
<body>
 
<h1>ayuda con esto porfa</h1>
<p>quiero que segun el texto del input se haga cierta opcion. que seria un alerto y el numero en que estoy</p>
<form name="calc">
<input name="n1">
<input type="button" value="calcular" onclick="seleccion()">
</form>
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de kip
Val: 553
Bronce
Ha aumentado 1 puesto en JavaScript (en relación al último mes)
Gráfica de JavaScript

me ayudan? quiero que según el numero del input se haga una acción diferrnte

Publicado por kip (107 intervenciones) el 07/06/2016 02:45:07
Hola, no te entendi lo que quieres, pero basandome en tu codigo he hecho esto, pruebalo y nos cuentas si se ajusta a lo que necesitas:

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
38
39
40
41
42
<!DOCTYPE html>
<html>
<head>
 
    <script type="text/javascript">
        var inputs = document.getElementsByClassName("class");
            function calcular() {
                var name_inputs = new  Array (inputs.length);
 
                for (var i = 0; i < inputs.length; i++) {
                    name_inputs [i]= inputs[i].name;
                }
 
                for (var i = 0; i < name_inputs.length; i++) {
                    switch (name_inputs[i]){
                        case 'n1' : evaluar(name_inputs[i],'LO QUE QUIERAS MOSTRAR') ; break ;
                        case 'n2' : evaluar(name_inputs[i],'LO QUE QUIERAS MOSTRAR EN EL SEGUNDO CASO') ; break ;
                    }
                }
            }
 
            function evaluar(attrname,mostrar){
                var attr_name = attrname;
                var text_input = document.getElementsByName(attr_name);
 
                for (var i = 0; i < text_input.length; i++) {
                    alert(text_input[i].value+' - '+ attr_name + ' - '+ mostrar);
                }
            }
    </script>
    <title>Page Title</title>
</head>
<body>
 
<h1>Ejemplo accion diferente segun atributo name</h1>
 
    <input type="text" name="n1" class="class" placeholder="Ingresa algun valor" />
    <input type="text" name="n2" class="class"  placeholder="Ingresa algun valor" />
    <input type="button" value="calcular" onclick="calcular()" />
 
</body>
</html>

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar