Question

I have a question, on how to best store local values of some form fields.

In my website, users use the keypad to keep a tally count of items. They can enter a label for the items they count. The problem is that each user apply different labels for their needs - and, each time they visit the labels are blank.

My sites are running through site44.com, which does not allow the use of server side php. So, in my research, I think using HTML5 localstorage may allow a user to keep the label after the exit the site?

Is this a correct interpretation?

Can someone give me a guide if I have, say 3 inputs - with different ids - how to set up the script?

Était-ce utile?

La solution

you can use the local storage like this :

var fn = document.getElementById("firstname").value;
localStorage.setItem("firstname", fn);

var ln = document.getElementById("lastname").value;
localStorage.setItem("lastname", ln);

var em = document.getElementById("email").value;
localStorage.setItem("email", em);

thus the clients browser will have these items set in their local storage. Now if a user visits the website afterwards. you can check for the value of localStorage and find the items of your need.

Suppose on users' next visit you want to send him a greet message ( he has not logged in ofcourse ) you can use a script like this below:

var name = localStorage.getItem("firstname");
alert("Hello"+name);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top