Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

99
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!