Error: [object HTMLInputElement]

-1

How do I resolve the error: [object HTMLInputElement]

The code should save the typed text in the field, and even giving F5 get saved, eg: same as the script for that site.

function digGet(){
    // Cria um item "usuario" com valor "Thiago Belem"
    var login = document.getElementById("user_login");
    window.localStorage.setItem('usuario', login);
    saveGet();
}

function saveGet(){
    // Depois, em outra página ou aba, recupera esse item
    var usuario = window.localStorage.getItem('usuario');
    document.getElementById('user_login').value = usuario;
}

function delGet(){

    // Remove o item
    window.localStorage.removeItem('usuario');
}

//Rodar no load do DOM
document.addEventListener("DOMContentLoaded", function(event){ 
    saveGet();
});
    
asked by anonymous 07.12.2017 / 22:20

1 answer

1

In this section, value is missing

function digGet(){
    //Correcao aqui
    //Antes login era um elemento do Dom e nao o valor do elemento
    var login = document.getElementById("user_login").value;
    
    
    
    window.localStorage.setItem('usuario', login);
    saveGet();
}
    
08.12.2017 / 02:03