You can get access to the query string by location.search
. Then you should be able to append it onto the form's action directly, something like the following:
// Get a reference to the form however, such as document.getElementById
var form = ...;
// Get the query string, stripping off the question mark (not strictly necessary
// as it gets added back on below but makes manipulation much easier)
var query = location.search.substring(1);
// Highly recommended that you validate parameters for sanity before blindly appending
// Now append them
var existingAction = form.getAttribute("action");
form.setAttribute("action", existingAction + '?' + query);
By the way, I've found that modifying the query string of the form's action directly can be hit-and-miss - I think in particular, IE will trim off any query if you're POSTing the results. (This was a while ago and I can't remember the exact combination of factors, but suffice to say it's not a great idea).
Thus you may want to do this by dynamically creating child elements of the <form>
that are hidden inputs, to encode the desired name-value pairs from the query.