Add parameters get value of a select / option in url

0

I have in the page that lists the properties of my site a search form and a select that does the ordering of the result.

Theproblem:Searchingtheformandpassingintheurlthevaluesviagetctr=0&min=20000&max=999999&suites=3etc.andsoonafterchoosingasortoptiontheurlhaslostthesevaluesbecausethepageisupdatedandsortstheoverallresult.WhenIselectasortoption,IwanttosorttheresultthatappearsonthepageandsoIneedtokeepthepreviousfilterparameterintheurlandaddthesortparameter.

I'msendingtheactiontosortthiswayandsoIlosethevaluesthatareintheurl:

$("select.ordenacao").change(function() {
        $("select.ordenacao").each(function() {
          str = $( this ).val();
          //alert(str);
            //$("#ordenar").submit();
            location.href = '?ordenacao=' + str;
        });
    });

Does anyone have any suggestions?

    
asked by anonymous 17.09.2015 / 22:54

1 answer

1

I suggest doing this in ajax:

$("select.ordenacao").change(function() {
        $("select.ordenacao").each(function() {
          str = $( this ).val();
              ordenar(str);
            //$("#ordenar").submit();
        });
});
var ordenar = function(str) {
       var saida = null;
             $.get('?ordenacao=' + str, function(e){
              saida = jQuery.parseJSON(e);       
             });
       return saida;
 };

Another option is to capture URL values and refresh again:

   $("select.ordenacao").change(function() {
            $("select.ordenacao").each(function() {
              str = $( this ).val();
              //alert(str);
                //$("#ordenar").submit();
                 location.href='?ctr='+getValueQS("ctr")+'&min='+getValueQS("min")+'&max='+getValueQS("max")+'&suites='+getValueQS("suites")+'&ordenar='+str;
            });
        });


    function getValueQS(key) {  
      return unescape(window.location.search.replace(new RegExp("^(?:.*[&\?]" + escape(key).replace(/[\.\+\*]/g, "\$&") + "(?:\=([^&]*))?)?.*$", "i"), "$1"));  
    }  
    
17.09.2015 / 23:22