1

On our home page we have a drop down menu that takes you to a country specific page.

We are using the the jquery change function to point the user to the correct country when the country is selected in a dropdown box.

If the user selects a country and and presses back after viewing the country page, and then wishes to view the same country page again, they have to select another country, press back and then select the previous desired country. Any way around this?

$(document).ready(function() {
$('select.jumpmenu').change(function(){ 
        if($(this).find("option:selected").val() != 'no_selection'){
            $.ajax({
                    type: "GET",
                    url: "/countries/jsontariff/" + $(this).find("option:selected").val(),
                    success: function(html){
                        window.location = "/recommend/";
                    }
            });
        }       
    });
});
AJFMEDIA
  • 2,093
  • 6
  • 29
  • 52

2 Answers2

1

Try to reset the select onload:

$(document).ready(function(){$('#selectList option:first').attr('selected',true)})
Dr.Molle
  • 116,463
  • 16
  • 195
  • 201
0

I would execute the same code on page load.

executeCountrySelection() {
    if($('select.jumpmenu').find("option:selected").val() != 'no_selection'){
        $.ajax({
                type: "GET",
                url: "/countries/jsontariff/" + $(this).find("option:selected").val(),
                success: function(html){
                    window.location = "/recommend/";
                }
        });
    }
}

$(document).ready(function() {

    //executes when the page loads
    executeCountrySelection();

    //then again when the select is changed
    $('select.jumpmenu').change(function() { executeCountrySelection(); });

});
ohmusama
  • 4,159
  • 5
  • 24
  • 44
  • You could also manually trigger the change event after assigning the change function, but I like your way better, as it seems a little more clear and forthright. – Wiseguy Apr 13 '11 at 15:29