简体   繁体   中英

Can't get the value from Email Input

I've downloaded a template form to sign in with bootstrap. When I try to get the value from the email or password field nothing happens.

the from looks like this

   <form class="form-signin">
            <img class="mb-4" src="https://getbootstrap.com/docs/4.3/assets/brand/bootstrap-solid.svg" alt="" width="72" height="72">
            <h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
            <input type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
            <input type="password" id="inputPassword" class="form-control" placeholder="Password" required>
            <div class="checkbox mb-3">
                <label>
                    <input type="checkbox" value="remember-me"> Remember me
                </label>
            </div>
            <button onclick="autentica()" class="btn btn-lg btn-primary btn-block" type="submit" >Sign in</button>
        </form>

and the function I'm trying to use looks like this:

<script>
    function autentica(){
    var mail = document.getElementById("inputEmail").value();
    alert(mail);
    if(document.getElementById("inputEmail").value() == "admin@admin.cl" && document.getElementById("inputPassword").value() == "admin"){
        document.location.href= "dashboard.html";
  }
}
</script>

Neither the alert nor the changing page works. The "dashboard.html" file is on the same folder.

Thanks in advance.

There is no function value() , but it's a (string) property value . So the correct syntax would be: var mail = document.getElementById("inputEmail").value;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM