i want keep selected values after page refresh, using jquery ui selectable https://jqueryui.com/selectable/
here's code sample of jquery selectable
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>jquery ui selectable - default functionality</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery- ui.css"> <link rel="stylesheet" href="/resources/demos/style.css"> <style> #feedback { font-size: 1.4em; } #selectable .ui-selecting { background: #feca40; } #selectable .ui-selected { background: #f39814; color: white; } #selectable { list-style-type: none; margin: 0; padding: 0; width: 60%; } #selectable li { margin: 3px; padding: 0.4em; font-size: 1.4em; height: 18px; } </style> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <script> $( function() { $( "#selectable" ).selectable(); } ); </script> </head> <body> <ol id="selectable"> <li class="ui-widget-content">item 1</li> <li class="ui-widget-content">item 2</li> <li class="ui-widget-content">item 3</li> <li class="ui-widget-content">item 4</li> <li class="ui-widget-content">item 5</li> <li class="ui-widget-content">item 6</li> <li class="ui-widget-content">item 7</li>
what's best approach achieve
just store value in cookie , reference in document.load method.
from quirksmode (including escaping characters)
function createcookie(name, value, days) { var expires; if (days) { var date = new date(); date.settime(date.gettime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.togmtstring(); } else { expires = ""; } document.cookie = encodeuricomponent(name) + "=" + encodeuricomponent(value) + expires + "; path=/"; } function readcookie(name) { var nameeq = encodeuricomponent(name) + "="; var ca = document.cookie.split(';'); (var = 0; < ca.length; i++) { var c = ca[i]; while (c.charat(0) === ' ') c = c.substring(1, c.length); if (c.indexof(nameeq) === 0) return decodeuricomponent(c.substring(nameeq.length, c.length)); } return null; } function erasecookie(name) { createcookie(name, "", -1); }
then create cookie in function using call:
createcookie('storedvaluename', selectedvalue, 1)
Comments
Post a Comment