简体   繁体   中英

Why my code doesn´t display a confirm popup in javascript?

I have the following function in a script linked to a form in html. When everything is ok the navigator should create 3 cookies and display a confirm popup but it doesn´t display the confirm popup but it creates the cookies. I have tried in firefox, I didn´t do it in chrome because it does extrange things with cookies so i prefered firefox

I'm new to stackoverflow so any advice will be appreciated

PD: some parts of the code are in Spanish (valor=value nombre=name contraseña=password)

function checkForm() {
  var emailValue = document.getElementById("email").value;
  var nombreValue = document.getElementById("nombre").value;
  var passValue = document.getElementById("pass1").value;
  if(comprobarCookie("email", emailValue)==false){
  if (CheckPass()) {//si las contraseñas coinciden, creamos la cuenta
    createCookie("email", emailValue);
    createCookie("nombre", nombreValue);
    createCookie("pass", passValue);
    var confirm=confirm("!Tu cuenta ha sido creada con éxito!")
    if (confirm==true) {
      location.replace("https://www.w3schools.com")
    } else {
      txt = "No has creado la cuenta";
    }
  } else {
    alert("las contraseñas no coinciden")
  }
  }else{
    alert("Ya existe una cuenta con ese email")
  }
}

Looks like you're using the reserved word confirm as your variable to test. Try replacing:

 var confirm=confirm("!Tu cuenta ha sido creada con éxito!")
if (confirm==true) {
  location.replace("https://www.w3schools.com")
} else {
  txt = "No has creado la cuenta";
}

with

var user_clicked = confirm("!Tu cuenta ha sido creada con éxito!");
if (user_clicked === true) {
  location.replace("https://www.w3schools.com");
} else {
  txt = "No has creado la cuenta";
}

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