title: Retrieve value from query string and send it in a form as HIDDEN VALUE - javascript
body: <p>I'm trying to figure how to post from an HTML to another page andm, in the meantime, insert values in the hidden form BEFORE send the form itself.</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;html&gt;
  
      &lt;head&gt;
  &lt;META HTTP-EQUIV="CONTENT-TYPE" CONTENT="TEXT/HTML;CHARSET=UTF-8"&gt;
  &lt;META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"&gt;
  &lt;META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"&gt; 
  &lt;META HTTP-EQUIV="EXPIRES" CONTENT="-1"&gt;
      
      
  &lt;script&gt;
  
  var param1var = getQueryVariable("TARGET");
  
  function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&amp;");
    for (var i=0;i&lt;vars.length;i++) {
      var pair = vars[i].split("=");
      if (pair[0] == variable) {
        alert("TARGET FOUND!");
          alert(pair[1]);
          return pair[1];
      
      }
    } 
      
  
    alert('Query Variable ' + variable + ' not found');
  }    
      
  &lt;/script&gt;    
      &lt;/head&gt;
      
      
  &lt;form name="LOGIN" action="/mynextpage/mypage.html" method="post"&gt;
        &lt;table&gt;
          &lt;tr&gt;
            &lt;td&gt;&lt;P&gt;&lt;span&gt;Username :&lt;/span&gt;&lt;/P&gt;&lt;/td&gt;
            &lt;td&gt;&lt;P&gt;&lt;input name="USER" type="text" value="" style="width:150px" /&gt;&lt;/P&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;&lt;P&gt;&lt;span&gt;Password :&lt;/span&gt;&lt;/P&gt;&lt;/td&gt;
            &lt;td&gt;&lt;P&gt;&lt;input name="PASSWORD" type="password" value="" style="width:150px" /&gt;&lt;/P&gt;&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/table&gt;
        &lt;/div&gt;
                      &lt;INPUT type=HIDDEN name="TARGET" value=param1var
      
      &lt;P&gt;
       &lt;input name="submit" type="submit" value="Login" /&gt;
       &lt;input name="Reset" type="reset" /&gt;
      &lt;/P&gt;
     &lt;/div&gt;
    &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The first part of the javascript code is able to capture a TARGET value I need to use: it is present (i'm calling it param1var) and I'm able to alert out just for confirmation.</p>
  
  <p>Now, in the form, I need to:
  - insert in the input hidden the value retrieved by the above code (so, the param1var value)
  - post the entire for to the page /mynextpage/mypage.html that will take username, password and the hidden value</p>
  
  <p>Can you help me on how to achieve it?
  I can use only html page as first page.</p>
  
  <p>Thanks</p>