Вопрос

I got a meany on my hands. I often use regular buttons instead of submit type buttons to have a bit more control over my forms. In this case I am trying to submit a form that is not present on the initial load, but is rather imported if the user makes the choices that lead to that.

To keep things simple I have added the .on("submit") to the same scope as where I trigger the submit, just to prevent jquery from getting confused.

        var form = $('form#create_topics');
        form.submit();
        form.submit(function(e) {  
            console.log("test");
            e.preventDefault();
            e.stopPropagation();
            return false;
        }

The submitting works, the preventing default processing does not. Not I have already tried .on("submit", function(e) and I have already tried form.submit(); after binding the .submit :)

I am guessing the reason its not working is due to my specific situation, any ideas?

Это было полезно?

Решение

var form = $('form#create_topics');
form.on("submit",function(e) {  
    e.preventDefault();
    if(condition matches){
        form.submit();
    }
});
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top