javascript - window.location.replace() not working in a form -
i'm trying set login form redirects user page after submitting form. neither window.location.replace()
, window.location.href
, or window.open()
seem work , can't figure out why. checked on developer tools , gives me no error.
here's javascript:
function loginutente(){ var email = document.getelementbyid('loginemail').value; var password = document.getelementbyid('loginpassword').value; var utente = localstorage.getitem(email); if( utente != null && json.parse(utente).password == password){ window.alert("login effettuato!"); window.location.replace("http:/www.google.it"); } else{ window.alert("utente o password non corretti"); } return false; }
and here's html:
<form class="form-group" id="formlogin" onsubmit="loginutente()"> <label>email</label> <div class="input-group"> <div class="input-group-addon"><span class="glyphicon glyphicon-user"></span></div> <input id="loginemail" type="text" name="nome" class="form-control" placeholder="indirizzo email" required ></input> </div> <br> <label>password</label> <div class="input-group"> <div class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></div> <input id="loginpassword" type="password" name="password" class="form-control" placeholder="password" required> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">close</button> <button type="submit" class="btn btn-success" ><span class="glyphicon glyphicon-send" ></span> login</button> </form>
putting return false
inside if not working either. google url of course placeholder url.
in form tag missed add return statement :
<form class="form-group" id="formlogin" onsubmit="return loginutente()">
so, form submitted without waiting response of function. , function code not executed.
Comments
Post a Comment