Uncaught TypeError: Can not read property 'type' of undefined - Javascript

0

I want to clean ALL the fields of the form that are of type "text", it works correctly for me but in the console I get the following error:

formulario.js:175 Uncaught TypeError: Cannot read property 'type' of undefined

Code:

function limpiar(){
    var cajas_texto = document.getElementsByTagName("input");
    for(var i=0; cajas_texto.length; i++)
        if(cajas_texto[i].type == "text")
            cajas_texto[i].value="";    
}
    
asked by omaza1990 25.05.2017 в 13:21
source

1 answer

0

You were accessing a position in the list that had undefined values due to an error in the for

function limpiar(){
    var cajas_texto = document.getElementsByTagName("input");
    for(var i=0; i < cajas_texto.length; i++)
        if(cajas_texto[i].type == "text")
            cajas_texto[i].value="";    
}
    
answered by 25.05.2017 / 13:23
source