Foros del Web » Programando para Internet » Javascript »

Problemas con getElementsByTagName

Estas en el tema de Problemas con getElementsByTagName en el foro de Javascript en Foros del Web. Buenas, a ver si hay alguien que me ayude con esto: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código HTML: Ver original < form name = "frm" > < input ...
  #1 (permalink)  
Antiguo 22/09/2008, 08:15
Avatar de Legoltaz  
Fecha de Ingreso: agosto-2008
Mensajes: 325
Antigüedad: 15 años, 8 meses
Puntos: 6
Problemas con getElementsByTagName

Buenas, a ver si hay alguien que me ayude con esto:

Código HTML:
Ver original
  1. <form name="frm">
  2. <input type="text" />
  3. <input type="text" />
  4. <input type="text" />
  5. </form>

Código JavaScript:
Ver original
  1. <script>
  2. var form = document.getElementById('frm');
  3. var inputs = form.getElementsByTagName('input');
  4. for(var i = 0;i < inputs.length;i++){
  5. inputs.disabled = true;
  6. }
  7. </script>
  #2 (permalink)  
Antiguo 22/09/2008, 08:18
Avatar de foreverOdd  
Fecha de Ingreso: noviembre-2007
Ubicación: Caracas
Mensajes: 489
Antigüedad: 16 años, 5 meses
Puntos: 14
Respuesta: Problemas con getElementsByTagName

y asi:

inputs[i].disabled
__________________
My path is lit by my own fire, I only go where I desire
  #3 (permalink)  
Antiguo 22/09/2008, 08:24
Avatar de Legoltaz  
Fecha de Ingreso: agosto-2008
Mensajes: 325
Antigüedad: 15 años, 8 meses
Puntos: 6
Respuesta: Problemas con getElementsByTagName

Me había olvidado de ese [i] pero, inexplicablemente (al menos para mí) sigue sin funcionar
  #4 (permalink)  
Antiguo 22/09/2008, 08:34
Avatar de foreverOdd  
Fecha de Ingreso: noviembre-2007
Ubicación: Caracas
Mensajes: 489
Antigüedad: 16 años, 5 meses
Puntos: 14
Respuesta: Problemas con getElementsByTagName

Dos errores.

1. Cuando se ejecuta el script los elementos no existen, bueno si lo colocas antes de los elementos.
2. la funcion getElementByTagName pertenece al document no al formulario

trata asi:

window.onload = function(){
var form = document.getElementById('frm');

var inputs = document.getElementsByTagName('input');

for(var i = 0;i < inputs.length;i++){

inputs[i].disabled = true;

}
}
</script>
__________________
My path is lit by my own fire, I only go where I desire
  #5 (permalink)  
Antiguo 22/09/2008, 09:10
Avatar de Legoltaz  
Fecha de Ingreso: agosto-2008
Mensajes: 325
Antigüedad: 15 años, 8 meses
Puntos: 6
Respuesta: Problemas con getElementsByTagName

Ahora lo he puesto así y ya funciona, gracias:

Código HTML:
Ver original
  1. <form name="frm">
  2. <input type="text" />
  3. <input type="text" />
  4. <input type="text" />
  5. <input type="text" />
  6. </form>

Código JAVASCRIPT:
Ver original
  1. <script>
  2. var inputs = document.frm.getElementsByTagName('input');
  3. for(var i = 0;i < inputs.length;i++){
  4. inputs[i].disabled = true;
  5. }
  6. </script>
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 13:48.