title: Javascript Function for Login Form Submit
body: <p>I have a login form on our new website design, and it has a username/password input, a drop-down select to choose which part of the site (control panels) to login to, and the submit button. As each panel has different needs to login from an external page, I wrote a Javascript function to match these. Unfortunately, it doesn't seem to work, and I am lost on where the issue is.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function changeAction(s)
  {
      var loginform = document.getElementById("frmLogin");
      panel_option = parseInt(s.options[s.options.selectedIndex].value);
  
      switch (login_option)
      {
          case 0:
              loginform.action = "https://www.domain.com/clients/dologin.php?goto=clientarea";
              loginform.username.name = "username";
              loginform.password.name = "password";
              break;
          case 1:
              loginform.action = "http://my.domain.com/templates/default/login.aspx";
              loginform.username.name = "UserName";
              loginform.password.name = "Password";
              break;
          case 2:
              loginform.action = "http://voicepanel.domain.com";
              loginform.username.name = "email";
              loginform.password.name = "password";
              break;
          default:
              loginform.action = "https://www.domain.com/clients/dologin.php?goto=clientarea";
              loginform.username.name = "username";
              loginform.password.name = "password";
              break;
      }
  }
  
  function loginSubmit()
  {
      var user = document.getElementsByName("username");
      var pass = document.getElementsByName("password");
  
      if(!user[0].value)
      {
          return;
      }
  
      if(!pass[0].value)
      {
          return;
      }
  
      document.getElementById("frmLogin").frmLogin.submit();
  }
  &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="wrap"&gt;
  &lt;!--Start Header--&gt;
  &lt;div id="header"&gt;
  &lt;a href="index.php" id="logo"&gt;&lt;span class="text_in"&gt;XFS&lt;/span&gt;&lt;/a&gt;
  
  &lt;!--User Login--&gt;
  &lt;div id="header_right"&gt;
      &lt;h2&gt;&lt;span class="text_in"&gt;User Login&lt;/span&gt;&lt;/h2&gt;
  
      &lt;form method="POST" name="frmLogin" id="frmLogin" onSubmit="javascript:loginSubmit();"&gt;
          &lt;input class="binput" name="username" style="margin-left: 40px;" value="Username"&gt;
          &lt;input class="binput" name="password" type="password" value="Password"&gt;
              &lt;select class="binput" style="margin-left: 40px; width: 130px;" onchange="javascript:changeAction(this);"&gt;
                  &lt;option value="0"&gt;Billing Panel&lt;/option&gt;
                  &lt;option value="1"&gt;Game Panel&lt;/option&gt;
                  &lt;option value="2"&gt;Ventrilo Panel&lt;/option&gt;
              &lt;/select&gt;
          &lt;input type="submit" class="blogin" value="Login" id="ButtonLogin"&gt;
      &lt;/form&gt;
  </code></pre>