LoginSignup
31
29

More than 5 years have passed since last update.

formのsubmit()を止めるときはpreventDefault()じゃなくてreturn falseを返す

Last updated at Posted at 2012-12-26

デフォルトのアクションを止めるなら全部preventDefault()かと思ったら、formの場合は違うみたい。

    $('form').submit(function() {
        var password = $('.password').val();
        var confirmation = $('.confirmation').val();
        if (password != confirmation) {
            $('.message.confirmation').text("パスワードが一致していません");
            return false;
        } else if (password.length < 8) {
            $('.message.password').text("パスワードは8文字以上で入力して下さい");
            return false;
        } else {
            this.submit();
        }
    });
31
29
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
29