Reputation: 27
I have
$('.bg').append('<input type="text" name="name">');
$('<input type="text" name="name">').appendTo('.bg > div:eq(0)').on('keyup', function(){
var link = $(this).val();
});
and I want to make variable "link" to appear in the input box every time the user enters the page. I think it should use local storing methods, but how do I do it?
I also tried using this
var set = localStorage.setItem(link);
var retrieved = localStorage.getItem(set);
$('.bg').append($('<input>').prop('type', 'text').val(retrieved));
Upvotes: 0
Views: 57
Reputation: 144729
You should use an identifier, then you can query the stored item by it's name:
// Storing an item
localStorage.setItem('link', link);
// Getting an item
var link = localStorage.getItem('link');
// Removing an item
localStorage.removeItem('link');
Upvotes: 1
Reputation: 1938
You can try using jQuery Cookie Plugin instead of localStorage that is not fully supported by the browsers.
Upvotes: 0