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

142
Views
Session storage not giving actual value

I'm trying to console.log a value taken from an input from session storage but it gives me " [object HTMLInputElement " but not the actual value of the input what can be done? Here's my code

let us = document.getElementById('us')
sessionStorage.setItem("user",us)
setTimeout(function() {
let h = sessionStorage.getItem("user")
console.log(h)
}, 200);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Your script is working correctly but document.getElementById('us') is html element, you store HTML element. I think you need value or something, you write or change like this document.getElementById('us').value or what you need to do.

about 4 years ago · Juan Pablo Isaza Report

0

As @Huseyint said, you must use <HTMLInputElement>.value to get the value of the input field. More info here. For example, your code would be rewritten like this:

const us = document.getElementById('us');
sessionStorage.setItem('user', us.value);
const h = sessionStorage.getItem('user');
console.log(h);

Or if you want to save all of the properties you could do something like this:

const us = document.getElementById('us');
sessionStorage.setItem('user', us);
const h = sessionStorage.getItem('user').value;
console.log(h);

Either one should work. Also, note that setItem() isn't a promise so you don't need the setTimeout.

Hoped this helped!

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!