sixthstar
sixthstar

Reputation: 85

Get and Set javascript value in localStorage

Hai I want to get javascript value using LocalStorage and stored a value in php. I don't know how to set a value so kindly provide me the solution.

var getdate1 = document.getElementById("eventDayName").innerHTML = selectedDate.toLocaleString("en-US", {
            month: "long",
            day: "numeric",
            year: "numeric"
        }); 


        localStorage.getItem('getdate1', val);

Upvotes: 1

Views: 2712

Answers (2)

Abhishek Tiwari
Abhishek Tiwari

Reputation: 143

Use this code:

// Store
localStorage.setItem("lastname", "Smith");

//get
localStorage.getItem("lastname");

Upvotes: 2

Mohammad Ali Rony
Mohammad Ali Rony

Reputation: 4915

For set a value in localStorage use window.localStorage.setItem like

window.localStorage.setItem('getdate1', JSON.stringify(getdate1));

var getdate1 =document.getElementById("eventDayName").innerHTML = selectedDate.toLocaleString("en-US", {
            month: "long",
            day: "numeric",
            year: "numeric"
        }); 
window.localStorage.setItem('getdate1', JSON.stringify(getdate1));

Upvotes: 2

Related Questions