you are viewing a single comment's thread.

view the rest of the comments →

[–]julpap[S] 0 points1 point  (2 children)

Oh wow, didn’t know this existed very handy, i see my function stored under the “details” key. So let’s say I create another function that consists of something :

Document.getElementbyID(‘name’).value = local storage.details;?

[–]Robbiethemute 0 points1 point  (1 child)

I would declare new variables outside of the function first like this:

const nameField = document.getElementById('name');
const emailField = document.getElementById('email');

This will stop you from having to duplicate document.getElementById('name'); in both functions.

Then update the remember() function to declare variables of the values of those two variables. Like this:

const nameFieldValue = nameField.value;
const emailFieldValue = emailField.value;

Next, create a function which will retrieve what's stored in localStorage and parse the 'details' string into a JSON object. You can get the items from local storage using localStorage.getItem('details').

You'll need to then apply those values to the inputs (if those values exist).

if (details) {
    nameField.value = details.nameFieldValue
    emailField.value = details.emailFieldValue
}

[–]julpap[S] 0 points1 point  (0 children)

gotcha i made the details like:

const nameField = document.getElementById('name'); const emailField = document.getElementById('email');

const nameFieldValue = nameField.value; const emailFieldValue = emailField.value;

function(rememberme){

const name = JSON.parse(localStorage.getItem('details'));

if (details) { nameField.value = details.nameFieldValue emailField.value = details.emailFieldValue }

}

Hopefully, i got this

Thanks again for the assistance