0
How do I resolve the error: [Object Htmlinputelement]
The code should save the text typed in the field, and even giving F5 stay saved, example: same as the script of this 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();
});
Please be clearer on your problem, as not even the full error message you put up. And do this editing the question, not in the comments. Start by describing what your code should do and what’s going on. Also put the full error message and work out a [mcve].
– Woss
The variable
login
is a gift element in the digGet method, I believe you should write the value.– N. Dias
Hello Jeferson, there are a lot of people around here who know JS :) Looking at your code
.setItem('usuario', login)
I see you’re trying to keep an element of the DOM inlocalStorage
that keeps only strings. That’s not going to work. I think what you want is to use.value
orinnerHTML
... guy:var login = document.getElementById("user_login").value;
– Sergio