mardi 4 août 2020

Javascript else if statement rules not firing

I am using this tutorial from https://www.formget.com/jquery-login-form/

All is exactly as per the tutorial. But the else if statement doesn't seem to fire when the php script echo is 'Successfully Logged in...'. The text is an exact match for the else if statement. Anyone any idea why this doesn't trigger?

$(document).ready(function(){
    $("#login").click(function(){
        var email = $("#email").val();
        var password = $("#password").val();
        // Checking for blank fields.
        if( email =='' || password ==''){
            $('input[type="text"],input[type="password"]').css("border","2px solid red");
            $('input[type="text"],input[type="password"]').css("box-shadow","0 0 3px red");
            alert("Please fill all fields...!!!!!!");
        }else {
            $.post("login.php",{ email1: email, password1:password},
            function(data) {
                if(data=='Invalid Email.......') {
                    $('input[type="text"]').css({"border":"2px solid red","box-shadow":"0 0 3px red"});
                    $('input[type="password"]').css({"border":"2px solid #00F5FF","box-shadow":"0 0 5px #00F5FF"});
                    alert(data);
                }else if(data=='Email or Password is wrong...!!!!'){
                    $('input[type="text"],input[type="password"]').css({"border":"2px solid red","box-shadow":"0 0 3px red"});
                    alert(data);
                } else if(data=='Successfully Logged in...'){
                    $("form")[0].reset();
                    $('input[type="text"],input[type="password"]').css({"border":"2px solid #00F5FF","box-shadow":"0 0 5px #00F5FF"});
                    alert("W" + data);
                } else{
                alert(data);
                }
            });
        }
    });
});

Aucun commentaire:

Enregistrer un commentaire