onSubmit重定向到依赖于值的网站

时间:2016-03-23 20:48:09

标签: javascript html forms login passwords

您好我正在尝试创建一个包含2或3个用户的简单登录表单,具体取决于登录重定向的用户应该是不同的网址。

到目前为止我的代码:

HTML       

  <h1 class="title">Logga in</h1>

<div class="grid__container">

  <form name="login" onSubmit="return validateForm();" action="some website url" method="post" class="form form--login">

    <div class="form__field">
      <label class="fontawesome-user" for="login__username"><span class="hidden">Username</span></label>
      <input name="usernameInput" id="login__username" type="text" class="form__input" placeholder="Username" required>
    </div>

    <div class="form__field">
      <label class="fontawesome-lock" for="login__password"><span class="hidden">Password</span></label>
      <input name="passwordInput" id="login__password" type="password" class="form__input" placeholder="Password" required>
    </div>

    <div class="form__field">
      <input type="submit" value="Sign In">
    </div>

  </form>

</div>

的JavaScript

        function validateForm() {
            var username = document.login.usernameInput.value;
            var password = document.login.passwordInput.value;
            var username1 = "user 1";
            var password1 = "1234";
            var username2 = "user 2";
            var password2 = "4321";
            if ((username == username1) && (password == password1)){
                return "www.google.se";
            }else if (username == username2) && (password == password2) {
                return "www.facebook.se";
            }else{
                alert ("Login was unsuccessful, please check your username and password");
                return false;
            }
        }

0 个答案:

没有答案