1

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);
1

2 Answers 2

2

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));

Sign up to request clarification or add additional context in comments.

5 Comments

The value will be set localStorage.setItem("getdate1", getdate1); //get var getval = localStorage.getItem("getdate1");
How can i set this value to php inside value <input type='text' id='inputid' value="" name='myDate' >
@sixthstar <input type"text" id="inputid" value = "<?php echo (isset($myDate))?$myDate:'';?>" name='myDate' >
@sixthstar set javascript or PHP valuse
Great Sir. That's Working fine..Thanks a lot.
2

Use this code:

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

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

8 Comments

I want to set a variable and assign to php value thats main logic. (e.g) <input type="hidden" value="{//localstorage variable}"
what does it mean here by php value
you can bind it with input by id of input
var x = localStorage.getItem("lastname");
$('#inputid').val(x);
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.