Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

88
Visualizações
Local Storage display problems

i'm trying to use localstorage to append recent city searches from user to a form element. The problem is now im very unsure of how to progress further if .innerHTML wipes out all text when it's putting anything into the element. the end goal would be for the form element to look something like

  1. athens
  2. paris
  3. chicago

any ideas on how to implement this?

new to local storage so would appreciate any help here's an example of the code :)

// HTML
<form class="recent-search" id="demo"></form>


// JAVASCRIPT
function setStorage() {
// here i'm trying to store nameValue to localstorage
        localStorage.setItem('', nameValue);
    }
    setStorage()
    function getValue() {
// now i'm getting nameofcity from localstorage
        return localStorage.getItem('nameofcity');
    }
// console logging it so i can make sure it's working (it is)
    console.log(getValue());
    function myFunction() {
// now i set the innerHTML of the element with the ID of "demo" to be "1. "nameofcity"
        document.getElementById("demo").innerHTML = '1. ' + localStorage.getItem('nameofcity');
    }
    myFunction();

if you'd like more context heres the github repository https://github.com/LukeMcHenry311/Server-Side-Weather

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You're saving the value to the key of an empty string and then trying to retrieve the key of nameofcity, which you probably didn't save it to. localStorage works by key-value pairs. You can always go to your browser's dev tools (usually by hitting F12), and under Application tab you can see what's in your local storage

It should be something like

function setStorage() {
        localStorage.setItem('nameofcity', nameValue);
 }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda