Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
130
rated 0 times [  135] [ 5]  / answers: 1 / hits: 17112  / 13 Years ago, sun, may 22, 2011, 12:00:00

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



<form action=/properties/search method=GET id=form_search>
<p>
<label for=price>Min price:</label>
<input type=text name=min_price id=min_price>
</p>
<p>
<label for=price>Max price:</label>
<input type=text name=max_price id=max_price>
</p>
<p>
<input type=submit>
</p>
</form>


When I submit my form, I have the following url :



http://.../properties/search?min_price=100000&max_price=200000



I want to change this url to have :



http://.../properties/search?price=100000,200000



To do that, I'm using JQuery and the JQuery querystring plugin :



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

// ???
});
});


How can I change (comment ???) the submit url ? I have tested the following instructions separately, but it does not work.



window.location = querystring;
window.location.href = querystring;
window.location.search = querystring;

More From » jquery

 Answers
23

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.
});
});

[#92122] Thursday, May 19, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
madelyn

Total Points: 449
Total Questions: 100
Total Answers: 100

Location: Seychelles
Member since Fri, May 7, 2021
3 Years ago
madelyn questions
Wed, Jul 28, 21, 00:00, 3 Years ago
Wed, Jul 14, 21, 00:00, 3 Years ago
Sat, Nov 7, 20, 00:00, 4 Years ago
Thu, Sep 3, 20, 00:00, 4 Years ago
;