Foros del Web » Programando para Internet » Javascript »

Contar solamente los input text.

Estas en el tema de Contar solamente los input text. en el foro de Javascript en Foros del Web. Como puedo contar solamente los input text y no todos los input ya que la funcion me considera todos los input, son 4 input en ...
  #1 (permalink)  
Antiguo 30/04/2012, 14:10
 
Fecha de Ingreso: octubre-2011
Mensajes: 153
Antigüedad: 12 años, 5 meses
Puntos: 7
Contar solamente los input text.

Como puedo contar solamente los input text y no todos los input ya que la funcion me considera todos los input, son 4 input en total, pero solo necesito obtener el valor de los text.

por favor.

Código Javascript:
Ver original
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function getElements()
  5. {
  6.     var i=document.getElementsByTagName("input");
  7.     alert(i.length);
  8. }
  9. </script>
  10. </head>
  11. <body>
  12.  
  13. <input type="text" size="20" /><br />
  14. <input type="text" size="20" /><br />
  15. <input type="text" size="20" /><br /><br />
  16. <input type="button" onclick="getElements()" value="How many input elements?" />
  17.  
  18. </body>
  19. </html>
__________________
Mi mail: [email protected]
  #2 (permalink)  
Antiguo 30/04/2012, 14:25
Avatar de emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 9 meses
Puntos: 1567
Respuesta: Contar solamente los input text.

Código Javascript:
Ver original
  1. var tags_input = new Array();
  2. function contar_it() {
  3. var tags_li2=document.getElementsByTagName('input');
  4. var n = 0;
  5. var i;
  6. for (i=0; i<tags_input .length; i++) {
  7. if (tags_input [i].type=='text') {
  8. n++;
  9. }
  10.  
  11. alert('hay' + n + ' input text');
  12.  
  13.  
  14. }

Saludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.

Etiquetas: funcion, html, input, solamente
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:51.