0

Hello i have an issue with this code that it's turning me mad (i'm a rookie in terms of JS language):

function procesarCambio(){
    if(obj.readyState == 4){
            if(obj.status == 200){
                document.getElementById("miDiv").innerHTML = obj.responseText;
                var persona;
                if(window.JSON)
                    persona = window.JSON.parse(obj.responseText);
                else
                    persona = eval( '(' + obj.responseText + ')' );
                if(window.sessionStorage){
                    sessionStorage.setItem("clave", persona.CLAVE);
                    sessionStorage.setItem("login", persona.LOGIN);
                    sessionStorage.setItem("nombre", persona.NOMBRE);
                    sessionStorage.setItem("email", persona.EMAIL);
                    sessionStorage.setItem("ultAcceso", persona.ULTIMO_ACCESO);
                    sessionStorage.setItem("foto", persona.FOTO);
                }
                //alert("Bienvenido" + sessionStorage.getItem("nombre")); //No tiene que ser un alert
                //setTimeout(window.location = "index.html", 0);
                document.getElementById("error").style.opacity = '0';
                document.getElementById("acierto").style.opacity = '1';
            }else{
            //alert("Nombre de usuario o contraseña incorrectos");//No tiene que ser un alert
            document.getElementById("acierto").style.opacity = '0';
            document.getElementById("error").style.opacity = '1';
            }
        }
}
function ocultar(){
    document.getElementById("error").style.opacity = '0';
    document.getElementById("login").focus();
    return false;
}

HTML:

<div id="acierto" class="popup acierto">
            <p>Welcome</p><a href="index.html"><img src="imagenes/x.png" height="32" width="32"></a>
            </div>
        <div id="error" class="popup error">
            <p>Error</p><a href="#" onclick="ocultar(); return false;"><img src="imagenes/x.png" height="32" width="32"></a>
        </div>

It handle the AJAX login request and then writes a message that can be both succesfull and error depending if the login gone right or not. It's all ok except for the fact that when i click on the X in the right corner of the success message, it calls the error function instead of go to index.html

1
  • Right, you're still clicking the X from the error dialog because it's still there, you just made it transparent. css problem. Commented Apr 20, 2016 at 17:40

1 Answer 1

1

use style.display = 'none' or 'block' instead of style.opacity

            document.getElementById("error").style.display = 'none';
            document.getElementById("acierto").style.display = 'block';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.