简体   繁体   中英

JavaScript if condition isn't redirecting to another page

I have a button, that when you click it, it will start a function, the objective of the function is to see if a bunch of statements are true, and if they are it should send me to another page

    <a href="">
                <button value="Registar" id="btn_registar" type="button" class="btn btn-default text-center" style="width: 90px; height: 30px; border-radius: 4px; cursor: pointer;" onclick="validar()">
                    <b>Registar</b></button>
            </a> <p id="reg_off></p>

My Function:

        function validar(){

        var nome = document.getElementById("nome").value;
        var username = document.getElementById("username").value;
        var password = document.getElementById("password").value;
        var conf_password = document.getElementById("conf_password").value;
        //var idade = .... FALTA O CALCULO DA IDADE

        if(nome == "" || username == "" || password == "" || conf_password == "") 
        {
            //alert("NOT WORKING");
            document.getElementById("reg_off").innerHTML = "ups";
            //WHEN I USE THE BUTTON ON THIS CONDITIONS, THE MESSAGE APPEARS BUT IT ONLY SHOWS FOR LIKE A MICROSECOND
        } else {
            alert("WORKED");
            window.location.href = "area_reservada.php";    
        }
    }

Change it to

window.location.href = "area_reservada.php";

Should help

(but this will set URL to area_reservada.php ) so you need to insert full URL in there

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