Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
155
rated 0 times [  159] [ 4]  / answers: 1 / hits: 81208  / 11 Years ago, thu, january 2, 2014, 12:00:00

I'm trying to save certain data into cookies, in such a way that if I jump from one page to another, the data entered should be saved and retrieved back on refresh.
I have a link:



<div class=esc-policy>
<a href=#>New Link</a>
</div>


before i fire the click event i need to save the entered the following data fields:



     <table class=form>
<tr>
<td class=label>
<label>Name*</label>
<input id=nameInput type=text maxlength=100/>
</td>
<td class=label>
<label>Description</label>
<input id=descriptionInput type=text maxlength=200 >
</td>
</tr>
</table>


I have something like this as my js:



if ($.cookie('back_to_url_onPage_referesh')) {
this.name.attr(value, $.cookie('name'));
this.description.attr(value, $.cookie('description'));
}


I'm not sure of how this works though. Can someone please help!!



Thanks in advance...



I am able to save the values in the cookie..however I still dont get how do i retrieve it while jumping back from one url to another. Ex:i have a url: ('#/link/create') where im creating this cookie..onclick of <a href=#>New Link</a>..i need to navigate to another url '#/new-link/create', enter few form fields on that page and when i hit the Save button- <a href=# class=btn>Save</a>, it should take me back to this url: ('#/link/create')..when i navigate between pages, the data is gone ofcourse, how to save that data on the UI side???


More From » jquery

 Answers
2
$(.esc-policy  a).on('click',function(){
var name = $(#nameInput).val(),
description = $(#descriptionInput).val();
$.cookie('back_to_url_onPage_referesh', 1);
$.cookie('name',name);
$.cookie('description',description);
});


If you add this code it will work as it is in your js. if you don't use cookie plugin in jquery. use native document.cookie expression, or extend jquery object with cookie function



you can use this plugin
https://code.google.com/p/cookies/wiki/Documentation#With_jQuery


[#73435] Tuesday, December 31, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
triston

Total Points: 545
Total Questions: 88
Total Answers: 94

Location: Lebanon
Member since Sun, Aug 2, 2020
4 Years ago
;