views:

55

answers:

4

At this moment we construct our search query in our website with java script. We have an input box for keyword and another input box for name and so on. If a user enters keyword: test the query looks like:

http://oursite.com/Search?keyword=test

if they enter keyword: test and name: john the string looks like:

http://oursite.com/Search?keyword=test&name=john

So the functionality is easy, take information from input boxed chain it, and then pass it to the window.location.

ok. now we want to do it with jquery, any ideas on how to start or plugins that will do this.

In case you are wondering, we want to do this to increase maintainability of our code and decrease dependency in one developer.

A: 
var keyword = $("#keyword")[0].value;
var name = $("#name")[0].value;
window.location = 'http://oursite.com/Search?keyword='+keyword+'&name='+name;
lod3n
this works, but for some reason every time the html is loaded the keyword=keyvar is cleared. I think I am doing something wrong. any ideas.
Geo
Cleared in the form, or cleared up on the URL bar?
lod3n
A: 

in addition to what @lod3n said you can use a url encoding plugin like this one in case the user enters spaces and other special chars.

Vincent Ramdhanie
A: 

I would set it up to utilize the jQuery serialize function.

Josh Stodola
A: 

I'd recommend jQuery Object String plugin. It enables you to do things like this:

var newUrl = $.query.set("section", 5).set("action", "do").toString(); 
> "?action=do&section=5&id=123"

Or this:

> action=view&section=info&id=123&debug&testy[]=true&testy[]=false&testy[]=true"
var arr = $.query.get('testy');
> ["true", "false", true]
Miguel Ping