How to disallow submit form if condition is false

user3383675

Situation:

<script>
    ...
    $('#trollMeNow').on('click', function () {
        if(condition)
            {
                SubmitThisFormNow();
            }
            else
            {
                BlockSubmitThisForm(); // <--- how to do that??
            }
    });
</script>
<input type="submit" id="trollMeNow"/>

I want to cancel submitting the form if condition returns false. How to do that?

Anoop Joshi

You can do like this

$('#trollMeNow').on('click', function () {

    if (condition) {
        SubmitThisFormNow();
    } else {
        return false;
    }
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related