$( "input[type=text], textarea, select" ).each( function()
{
var id = $( this ).prop( "id" ) + "-store";
var previous = localStorage.getItem( id );
if( previous !== null )
{
$( this ).val( previous );
}
$( this ).change( function()
{
localStorage.setItem( id, $( this ).val() );
} );
} );
This can be extended to checkboxes too, but it's slightly different:
$( "input[type=checkbox]" ).each( function()
{
var id = $( this ).prop( "id" ) + "-store";
var previous = localStorage.getItem( id );
if( previous !== null )
{
$( this ).prop( "checked", previous === "true" );
}
$( this ).change( function()
{
localStorage.setItem( id, $( this ).prop( "checked" ) );
} );
} );
[center][/center]
Somebody # 24/05/23 10:24
Somebody # 20/09/24 01:30
Add Comment