Skip to content

Instantly share code, notes, and snippets.

@zlojkashtan
Forked from h4/t.js
Created August 11, 2017 12:28
Show Gist options
  • Select an option

  • Save zlojkashtan/0f8fe90e137a4a360f2c089c2aaebd77 to your computer and use it in GitHub Desktop.

Select an option

Save zlojkashtan/0f8fe90e137a4a360f2c089c2aaebd77 to your computer and use it in GitHub Desktop.

Revisions

  1. @h4 h4 created this gist Jul 8, 2015.
    18 changes: 18 additions & 0 deletions t.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    $(function() {
    var $citySelect = $('#city-select'),
    STORAGE_ITEM_NAME = 'saveCity';

    $citySelect.on('change', function () {
    var url = $citySelect.val();

    if (url !== '') {
    localStorage.setItem(STORAGE_ITEM_NAME, url);
    window.location = url;
    }
    return false;
    });

    if(localStorage.getItem(STORAGE_ITEM_NAME)){
    $citySelect.val(localStorage.getItem(STORAGE_ITEM_NAME));
    }
    });