title: How To Create HTML Form That Accepts Field Values As URL Parameters
body: <p>The goal is to create a standalone HTML form that pre-fills fields with text passed as URL parameters. </p>
  
  <p>To test, a plain html file was created with a single textarea named "test". When <a href="http://myserver.com/simpleform.html?test=sampletext" rel="nofollow noreferrer">http://myserver.com/simpleform.html?test=sampletext</a> is typed in the address bar, the text passed as the parameter test does not populate the field.</p>
  
  <p>I thought that the only thing necessary to pre-fill text to a field in a web form was to know the name of the target field. When that failed, I attempted to use some Javascript that would execute on load that I found on another answer provided by Cerbrus here: /a/14070223</p>
  
  <p>But there was no change in the result. When I entered <a href="http://myserver.com/simpleform.html#test=sampletext" rel="nofollow noreferrer">http://myserver.com/simpleform.html#test=sampletext</a> in the address bar, the passed text would not appear in the field. Here is the code I have currently:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;body onload="acceptParam()"&gt;
  
  &lt;script&gt;
  function acceptParam() {
    var hashParams = window.location.hash.substr(1).split('&amp;'); // substr(1) to remove the `#`
    for(var i = 0; i &lt; hashParams.length; i++){
        var p = hashParams[i].split('=');
        document.getElementById(p[0]).value = decodeURIComponent(p[1]);;
    }
   }
  &lt;/script&gt;
  &lt;center&gt;
  &lt;textarea rows="15" name="test" cols="50"&gt;
  
  &lt;/textarea&gt;
  &lt;/center&gt;
  
  
  
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Is it even possible to create a web form that accepts field values as URL parameters using a single standalone HTML file? I don't need to submit the data, only to populate the field with text passed in the URL.</p>