javascript - Input value of cookie -
i want apologize in advance if repeat question. want able input value of previous page using cookies jquery.
i know how set/get/remove i've never tried use values input fields.
can give guidance/example on how accomplish this?
jquery:
//plug-in// <script src="/path/to/jquery.cookie.js"></script> <script> //set , expire form 1// $(document).ready(function(){ var date = new date(); var minutes = 5; date.settime(date.gettime() + (minutes * 60 * 1000)); $.cookie('name1', 'value1', { expires: date, path: '/' }); $.cookie('name2', 'value2', { expires: date, path: '/' }); $.cookie('name3', 'value3', { expires: date, path: '/' }); $.cookie('name4', 'value4', { expires: date, path: '/' }); }); </script> <script> //get form 2// $(document).ready(function(){ $.cookie('name1'); $.cookie('name2'); $.cookie('name3'); $.cookie('name4'); //remove form 2// $.cookie('name1', null); $.cookie('name2', null); $.cookie('name3', null); $.cookie('name4', null); }); </script>
when read cookie value, in order value useful, have assign variable. can use variable manipulate input element in current page:
//page 2 $(document).ready(function(){ var name1 = $.cookie('name1'); $('input[name=page1_name1]').val( name1 ); });
where input element in page 2 is:
<input type="text" name="page1_name1"/>
Comments
Post a Comment