title: Sync HTML form with URL query string?
body: <p>On websites such as eBay, upon returning to a search page, the search options are all filled in. I'd like to do the same with my website, where currently, returning to the search page returns the correct search results but the search form is empty.</p>
  
  <p>The two approaches I've seen to this so far:</p>
  
  <ol>
  <li>Have the form written in HTML, use JS to parse query string and set form values.</li>
  </ol>
  
  <p><a href="https://stackoverflow.com/questions/5422265/how-can-i-pre-populate-html-form-input-fields-from-url-parameters#comment6139300_5422346">How can I pre-populate html form input fields from url parameters?</a></p>
  
  <ol start="2">
  <li>Generate the form in JS with any values in the query string, this will make a blank form if there's no query string given.</li>
  </ol>
  
  <p><a href="https://stackoverflow.com/questions/1521378/query-string-for-pre-filling-html-form-field">Query String for pre-filling html form field</a></p>
  
  <p>Both these solutions seem hack-y. I'd imagine that this is a common task, is there a standard or clean method to do this in one or two lines?</p>
  
  <p>There is obviously something that serializes the fields from a form to a query string, there should be a way to use that in reverse to take the query string and fill in the form fields, without having to "roll your own" loop in JS.</p>