Personally, I use the QueryParser() constructor found here.
This has the following advantage over the gup() function posted by Matthew Nie :
- Parses the query string once and stores all parameters as properties of an object.
It also allows :
- Stored parameters to be changed or cleared
- New parameters to be added
- A new query query string to be built from the currently stored parameters
- Links to be built with
href containing a query string built from the currently stored parameters.
In conjunction with jQuery, use QueryParser() as follows :
Page 1
- Submit the form as described by Maksym Kozlenko.
Page 2
- Install
jQuery and QueryParser() on the page
- For each form field,
$("#formID [name='fieldName']").val($q.fieldName).
Or to save having to hand-code each form field individually :
$.each($("#myform")[0].elements, function(index, element) {
$(element).val($q[element.name]);
});
Thus, the form on the page 2 will be populated with the values entered/selected on page 1.
DEMO