Skip to content Skip to sidebar Skip to footer

How To Change The Querystring When I Submit My GET Form Using JQuery?

Suppose that I have a simple form in my page like this :

Solution 1:

You're almost there. Intercept the submit event (as you are doing), extract the min and max values, build your url and set window.location.href

$(document).ready(function() {
    $("#form_search").submit(function(event) {
        event.preventDefault();
        $this = $(this);
        // var url = rewrite_interval_qstring();
        var min_price = $('#min_price').val();
        var max_price = $('#max_price').val();
        var url = $this.attr('action') + '?price=' + min_price + ',' + max_price;
        window.location.href = url;
    });
});

Solution 2:

You need to prevent the default submit action from happening

$(document).ready(function() {
    $("#form_search").submit(function(event) {
        event.preventDefault(); // <-- add this
        var querystring = rewrite_interval_qstring();
        // querystring equals "?price=100000,200000" -> exactly what I want !

        window.location.href = querystring; // <-- this should work.
    });
});

Solution 3:

Answer by Rob Cowie is one method. Another one is adding a hidden field named "price" and fill it before submitting it with the value you want.


Post a Comment for "How To Change The Querystring When I Submit My GET Form Using JQuery?"