Home > database >  Cancel Form without validation
Cancel Form without validation

Time:04-28

I have an HTML Form which has two Buttons of the type "submit". One for submitting the form and one for cancelling the form.

enter image description here

To validate the input, I added a event listener, which reacts when somebody submits the form:

    $("form").submit(function (e) {
    if (textboxContainsValues){
       return true:
    }
       else false;
    });

My problem is, when I click on "Cancel" (abbrechen), it also goes into the event listener and checks the textboxes for values.

Is there a way to distinguish those two actions with my above listener?

thanks in advance

CodePudding user response:

As pointed out in the comments you could either simplify your function to just return textboxContainsValues; or even better use type="button" instead of type="submit" on your cancel button.

  • Related