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

100
Visualizações
How to retrieve data from local storage and display it on form's check box or dropdown menu in JavaScript

I have a form which contains radio check and dropdown menu after selection and check data goes to local storage and there is button for update when click it back again to the form again filled by data from local storage but I can't make the radio check be checked according to data also the option not select in the selected menu. code should be in JavaScript only

        <select class="country" >
            <option value="0">Choose Your Country</option>
            <option value="1">UAE</option>
            <option value="2">USA</option>
            <option value="3">UK</option>
        </select>
        <p id="type">Gender:</p>
            <input type="radio" value="male" name="gender" class="gender">
            <label for="male">Male</label>
            <input type="radio" value="female" name="gender" class="gender">
            <label for="female">Female</label> 
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

For checkbox

let checkboxes = [checkboxOne, checkboxTwo, checkBoxThree];
let checkboxLabels = [labelOne, labelTwo, labelThree];

for (let i = 0; i < checkboxes.length; i++) {
    if (window.localStorage.getItem('checkboxValue') === checkboxLabels[i].textContent) {
        checkboxes[i].setAttribute('checked', 'checked');
    }
}

For drop down

let options = [optionOne, optionTwo, optionThree];

for (let i = 0; i < options.length; i++) {
    if (window.localStorage.getItem('dropdownValue') === options[i].value) {
        options[i].setAttribute('selected', 'selected');
    }
}

Instead of putting elements inside arrays, you can use querySelectorAll

let checkboxes = document.querySelectorAll('#form input[type="radio"]');
about 4 years ago · Juan Pablo Isaza Relatório

0

You can access localStorage on windows object. And change values using queryselectors or pass a function to the value.

document.querySelector(<selector>).<propperty you want to set> = window.localStorage.<value tou want to retieve>
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