How can i pass multiple values of fropdowns in url?
Hey guys,
I'm currently creating a project with Codeigniter and i have some dropdowns which will filter my db results using "GET" method in url.
What i want is to pass or replace (if its already in the url) the value of the selected dropdowns ONLY, like an array.
A guy helped me on some point but on selecting another dropdown box the value in url is replaced with the last chosen. Could you please help me on that?!
P.S.: If you faced the same (filtering results) and you have a different proposal on how to achieve this, please do it freely!!
Thank you!!
MyJquery code:
- $('#filters select').change(function(){
- let filters = [];
- $('#filters select').each(function(){
- const string = $(this).attr('id');
- const value = $(this).val();
- if(value != '') {
- filters.push(string + '=' + value);
- }
- });
- window.location.search = filters.join('&');
- });
My html dropdowns code:
- <div class="col-lg-2" id="filters">
- <div class="form-group mt-3">
- <select class="form-control filter-selection" id="petStatus">
- <option value="">-- Status --</option>
- <option value="1">Lost</option>
- <option value="2">Found</option>
- </select>
- </div>
- <div class="form-group input-group">
- <select class="form-control filter-selection" id="petType">
- <option value="">-- Choose type --</option>
- <option value="1">Cat</option>
- <option value="2">Dog</option>
- <option value="3">Other</option>
- </select>
- </div>
- </div>