Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
Add GET request value to the end of a URL

I have a WooCommerce form on the category pages which allows the user to select the number of products to be shown on the page. The values are 24, 48 and all. When one of the options is selected, the form is submitted. The issue I have is the GET value is replacing the existing values in my URL whereas I need the value adding to the end of the URL.

For example, if my URL is: www.example.com/?s=cars&post_type=product&type_aws=true and I update the form, the URL becomes: www.example.com/?show=48 whereas I need it to be added to the end like so: www.example.com/?s=cars&post_type=product&type_aws=true&show=48

Here is my HTML Form:

<form class="woocommerce-results-per-page" method="get">
  <span>Show</span>
    <select class="autosubmit" name="show">
      <option value="48">48</option>
      <option value="24">24</option>
      <option value="-1">All</option>
    </select>
    <input type="hidden" name="orderby" value="rating">
</form>

Here is my jQuery

$(function(){
    $(document).ready(function()
        {
             $( '.autosubmit' ).each( function()
           {
                $( this ).on( 'change' , null , function()
             {
                $( this ).parents( 'form' ).submit();
            });
        } );
    });

});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try this:

$(document).ready(function () {

        let select = $('.autosubmit');
        url = new URL(window.location.href);
        show = url.searchParams.get("show");
        if (show !== null) {
            select.find(`option[value="${show}"]`).prop('selected',true)
        }


        select.each(function () {
            $(this).on('change', null, function () {
                let url = window.location.search;
                let params = url.substring(1, url.length).split('&');
                let hidden_inputs = '';
                let form = $(this).parents('form');

                $.each(params, function (i, el) {
                    let param = el.split('=');
                    if (form.find(`select[name="${param[0]}"],input[name="${param[0]}"]`).length == 0) {
                        hidden_inputs += `<input type="hidden" name="${param[0]}" value="${param[1]}">`;
                    }
                });
                
                form.prepend(hidden_inputs).submit();
                
            });
        });
    });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!