jeudi 5 mai 2016

Javascript get URL params, then trigger click on checkbox

I got an GET request on a webpage, with multidimensional checkboxes. The GET request would look like this:

&company_state[AKERSHUS]=AKERSHUS&company_state[AKERSHUS][]=ASKER&company_state[SOGN+OG+FJORDANE]=SOGN+OG+FJORDANE&company_state[SOGN+OG+FJORDANE][]=ASKVOLL

As you can see, company_state is an array, wich again contains an array of values.

Is it possible to use jQuery or plain JS to grab the URL parameters, and trigger a click on the checkboxes with the same name (company_state, company_municipality) and value?

I tried using this, but this doesn't seem to work in this purpose to grab the params.

function getQueryParams(qs) {
  qs = qs.split("+").join(" ");
  var params = {},
    tokens,
    re = /[?&]?([^=]+)=([^&]*)/g;
  while (tokens = re.exec(qs)) {
    params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
  }
  return params;
}

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire