Set searchParams.get () to a specific code or similiar

0

I'm using the following script for a Select

$(function() {
  $('#categoria').on('change', function() {
    var url = "https://" + window.location.hostname + "/search?q=" + $(this).val();
    if (url) {
      window.location.href = url;
    }
    return false;
  });
var url_ = new URL(location.href);
var variavel = url_.searchParams.get("q");
$("#categoria").val(variavel);
});

And this is working, the problem is that when I use a second code that complements the same, it does not find the value and is blank

Example of the second code (there are 12 more, just changing the value):

function automovelf( {window.location.href="https://"+window.location.hostname+"/search?q="+$('#categoria').val()+"%20label:Automovel";}

That is, if in the first select I select "Car" for example, the url will look like this: link and the select will select the car option. But if in the second list I select "Automovel" for example, the url will be: link however the select would be blank. I would have noticed how to modify this part of the first code:

var url_ = new URL(location.href);
var variavel = url_.searchParams.get("q");
$("#categoria").val(variavel);

Making it check the "q=" parameter until "% 20", that is, if the URL is " link " the selected select will be "label: Car".

    
asked by anonymous 29.01.2018 / 03:41

0 answers