Code Monkey home page Code Monkey logo

preservejs's Introduction

PreserveJS

Hello. This one is a tiny library that helps you to save entered values of HTML elements. It is actually pretty lame.

This helps to not lose form values on tab close/page reload. If you need something super-stable -- write your own.

Usage

All you have to do is add the script in your html file:

<script type="text/javascript" src="preserve.js"></script>

And then add the "preserve" property to any html element:

<input type="checkbox" id="checkit" preserve/>

This will save element value every time it changes, in a localstorage.

Preservation ID

Values are saved in an identifier which, if no value for "preserve" attribute is set, is generated, url- and elementID-dependant. You can alter this by specifying the value for preserve attribute

<input type="checkbox" id="checkit" preserve="check_it"/>

Preservation ID generation

By default the values are saved by a key formed from current url + hash symbol + id or name of element. (Name is used if id is empty). Say, for this:

<input type="checkbox" id="checkit" preserve/>

The value, on http://localhost/preserve will be saved in a key called localhost/preserve#checkit. This means that, say, on http://localhost/preserve?mode=gallery page it will not be preserved, even if input has same id.

Future Plans

  • Support for select multiple

Warning

LocalStorage is limited to 5MB. So maybe consider not using this for large input fields etc.

preservejs's People

Watchers

James Cloos avatar Ilia Andrienko avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.