[Solved] Select menu options not getting selected when we navigate to other pages


Here’s how your jQuery code could look like:

This will get the path name of the current URL and select that value in the drop down.

$(document).ready(function(){

    var url = window.location.pathname; //e.g: "http://www.test.com/index2.html";
    var pagename = url.split("https://stackoverflow.com/").pop();

    $("select").val(pagename);

    $("select").change(function() {  
        window.location = $(this).find("option:selected").val();
    });

});

This solution also assumes that you’re not using query strings.

0

solved Select menu options not getting selected when we navigate to other pages