title: Javascript - Pass URL/Hyperlink parameters to fill input fields of loginpage
body: <p>I would like to write a function with JavaScript to be able to fill out form fields in advance via hyperlink - passing parameters from the address line (URL parameters) to the form fields.</p>
  <p>URL: [...]/login.aspx?firstname=My&amp;lastname=Test</p>
  <p>After clicking the link, both input fields of the login area should now already be prefilled with &quot;My&quot; and &quot;Test&quot;.</p>
  <p><strong>head-part:</strong></p>
  <pre><code>    &lt;script type=&quot;text/javaScript&quot;&gt;
  function getUrlParameter(par) {
      var value = '';
      var UrlParameter = window.location.search;
  
      if (UrlParameter != &quot;&quot;) {
          var i = UrlParameter.indexOf(par + &quot;=&quot;);
          if (i &gt;= 0) {
              i = i + par.length + 1;
              var k = UrlParameter.indexOf(&quot;&amp;&quot;, i);
              if (k &lt; 0) {
                  k = UrlParameter.length;
              }
              value = UrlParameter.substring(i, k);
              for (i = 0; i &lt; value.length; i++) {
                  if (value.charAt(i) == '+') {
                      value = value.substring(0, i) + &quot; &quot; + value.substring(i + 1, value.length);
                  }
              }
              value = unescape(value);
          }
      }
      else {
          document.write(&quot;error&quot;);
      }
      return value;
  }
  
  function init() {
      var firstname= getUrlParameter(&quot;firstname&quot;);
      document.Kontakt.Firstname.value = firstname;
  
      var lastname= getUrlParameter(&quot;lastname&quot;);
      document.Kontakt.Lastname.value = lastname;
  }
  </code></pre>
  <p><strong>body-part</strong></p>
  <pre><code>&lt;body onload=&quot;init()&quot;&gt;
  
  &lt;form id=&quot;frmStartseiteMaster&quot; name=&quot;Kontakt&quot; runat=&quot;server&quot; class=&quot;ym-form ym-full ym-form-login ie_display&quot; autocomplete=&quot;off&quot; data-alert=&quot;&quot;&gt;
  
  &lt;input type=&quot;text&quot; name=&quot;Firstname&quot; id=&quot;Firstname&quot; /&gt;
  &lt;input type=&quot;text&quot; name=&quot;Lastname&quot; id=&quot;Lastname&quot; /&gt;
  </code></pre>
  <p>The displayed error is:</p>
  <p>Uncaught TypeError: Cannot read property 'Firstname' of undefined</p>
  <p>I have been sitting on this problem for a while and can't get any further. I would appreciate your help.</p>
  <p>Best regards,
  Chrissy</p>