Tudor P.
Tudor P.

Reputation: 27

Storing an user input

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

Answers (2)

Ram
Ram

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

Reference

Upvotes: 1

Daniele
Daniele

Reputation: 1938

You can try using jQuery Cookie Plugin instead of localStorage that is not fully supported by the browsers.

Upvotes: 0

Related Questions