Anyone have a JavaScript trick to create a web form that builds a URL to send users to a pre-populated search?
I'm trying to build a form that can add various variables to a URL prior to submitting, conducting a search with prepopulated criteria. For example, I'd like the web form to say:
Find: [ ] Widgets [ ] Doodads [ ] Gizmos
Priced: [ ] Below $5 [ ] Below $500 [ ] Below $5000
The equivalent plain, non-trick HTML would look like this:
<input type="checkbox" name="type" value="widgets">
<input type="checkbox" name="type" value="doodads">
<input type="checkbox" name="type" value="gizmos">
<input type="checkbox" name="maxprice" value="0005">
<input type="checkbox" name="maxprice" value="0500">
<input type="checkbox" name="maxprice" value="5000">
But, instead of the form sending information the usual way, selecting the various elements would instead add, remove, or change variables within a URL to which it would send users when they clicked "Submit." For example, changing the above fields would, behind the scenes, build URLs like:
http://www.search.com/query?maxprice=0005
http://www.search.com/query?product=doodads
http://www.search.com/query?product=doodads&maxprice=0500
Users could not select various fields without breaking the URL, but also combine any series of variables available. Clicking submit would finalize the search URL and send them straight to the results. Presume that the receiving site would understand the variable names and values sent in the URL.
This seems pretty straightforward, but I can't find example code to do exactly this. Any pointers would be much appreciated!
posted by breaks the guidelines? at 12:26 PM on January 23, 2008 [1 favorite has favorites]