jQuery querystring

When select option is changed, link to new page with query string


$(document).on("change", "#province", function(e) {
  var province = $(this).val()

  var params = new URLSearchParams(location.search)
  params.set('province', province);

  var url = `${location.pathname}?${params}`
  window.history.replaceState({}, '', url);
  document.location = url;
})


Example:

//create new querystring

example.com # example.com?province=abc


// update existing querystring

example.com # example.com?province=def