JavaScript - remember me functionality in javascript .

Asked By mohan n on 21-Oct-18 10:11 AM
$(function () {
    if (localStorage.chkbx && localStorage.getItem(chkbx) !== '') {
        $('#modal_login_remember').attr('checked', 'checked');
        $('#modal_login_email').val(localStorage.getItem(usrname));
        $('#modal_login_password').val(localStorage.getItem(pass));
    } else {
        $('#modal_login_remember').removeAttr('checked');
        $('#modal_login_email').val('');
        $('#modal_login_password').val('');
    }

    $('#modal_login_remember').click(function () {

        if ($('#modal_login_remember').is(':checked')) {
            // save username and password
            localStorage.setItem('usrname', $('#modal_login_email').val());
            localStorage.setItem('pass', $('#modal_login_password').val());
            localStorage.setItem('chkbx', $('#modal_login_remember').val());
        } else {
            localStorage.setItem('usrname', '');
            localStorage.setItem('pass', '');
            localStorage.setItem('chkbx', '');
        }
    });
});