1
I have a dynamic table, which changes according to the user’s select done in HTML. However, every time the page updates the selected option ends up changing too.
I thought of two possibilities that might work out for what I want:
- Create a variable and pass the current choice to that variable. Create a button called "Load" and every time this button is triggered, it will press whatever is inside that variable;
- Best way: create a default option and go updating this default option according to the user’s choice.
The first option I even managed to do, but it keeps "updating" the page and losing value.
Here is the example of the code: http://jsfiddle.net/kBQdS/247/
Thank you,
Thanks Tobias, the idea worked. The problem is that as there are several people filling out the same form, if one updates, it ends up updating everyone. Can you do something like this where each form is unique?
– user2287892
@user2287892 the localStorage exists only in the client (Browser) and cannot be accessed on the server, so if people are using different computers, then they are isolated. If more than one person uses the same computer and browser, you will have to add a unique key to the registry name in localStorage, such as an email... eg: localStorage("[email protected]", value).
– Tobias Mesquita
The form is accessed via server, IE, it ends up taking the localStorage from the same place. But you could not create an array as a single key or is not allowed?
– user2287892
Just to complement, I have an ID that is unique to each form. How could I use it to my advantage, i.e., store the localStorage within that ID, as a single key?
– user2287892
I gave an evolved in my question, I am able to bring the number automatically generated by the form as "key" (I can visualize through the console), the problem that every time I update the page, it loses the information. This was not happening before. var nsit = Document.getElementById("nsit"). value; localStorage.setItem(nsit, this.value); var montadoraAtual = localStorage.getItem('nsit'); $('.assemblers'). val(montadoraAtual). Trigger("change"); What may be wrong?
– user2287892
@user2287892 you are going to
string 'nsit'
and not thevariavel nsit
to thelocalStorage.getItem(nsit)
.– Tobias Mesquita
Now it’s all worked out. In addition to what you said, I had to put var nsit = Document.getElementById("nsit"). value; out of $('. assemblers'). change(Function() Thanks for the help
– user2287892