Results 1 to 2 of 2

Thread: How to refresh a page and retain the same selection

  1. #1
    Join Date
    May 2012

    How to refresh a page and retain the same selection

    Hi ,

    I am developing a webpage using LAMP where the programming language is PERL.

    My page has a table in it and above the table columns there is drop-down which filters the table data. This filter is implemented by Javascript. If I choose 'all' from the drop-down it shows the entire table data and if other
    values are selected then only those relevant data it shows. By default if not
    selected anything from drop-down, it shows all the data of the table.

    The problem is , if I refresh the page then irrespective of what value was selected from drop-down, it shows the default data only. How can I implement the feature so that even if I refresh it will bring the table-data depending on the last selected value from the drop-down.

    Please help.


  2. #2
    Join Date
    Oct 2007
    Vienna, Austria
    This is for the JavaScript forum.

    You do it this way: Create a string representation for the current filter (like the value of the option from the select tag), then store that to the fragment part of the URL. Then add a JavaScript to the end of the body that will check if a URL fragment is present and apply the appropriate filter.

    It could look something like this, if you use jQuery:

    // after a dropdown has been selected:
    location.hash = $(selected_option).val();
    $(document).ready(function() {
        var fragment = location.hash.replace(/^#/, '');
        if (fragment) {
    N.B. Another possible place of storing the selection would be a cookie if you don't like to alter the URL fragment.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center