There is a form <form action="page.php" onclick="welcomeAnimate()" method="POST" > , in theory, if welcomeAnimate() returns false , then the page.php transition will not be. But for some reason, in any case, the transition is carried out

  function welcomeAnimate() { var enter = document.getElementById("enter") var login = document.getElementById("login") var password = document.getElementById("password") login.style.display = "none" var box = [login, password] enter.onclick = function () { var display = login.style.display if (login.value == "" && password.value == "") { if (display == "none") { for (var a in box) { box[a].style.display = "block"; } } else if (display == "block") { for (var a in box) { box[a].style.display = "none"; } } else { alert("Sorry undefined value") } return false; } else { return true; } } } 


    3 answers 3

    Use not onclick , but onsubmit . And the function that processes the form should just check the values ​​(in your code, some other handler is also hung)

      Not really friendly with javascript, but maybe onclick = "welcomeAnimate ()" still hang on the form button? Although she, something nonsense came up with something. :-)

      • No, I have already tried it - Zow
      • in fact, all this madness implies that click bubbl` to form - karmadro4

      Hey. It is necessary to catch event events of submit. It is possible to implement using jQuery, like this:

       $("form").submit(function() { // проверяем значение поля, если равно 'correct' то возвращаем true, иначе false if ($("input:first").val() == "correct") { return true; } return false; }); 

      Try this, it can be useful :)