1

I have initialized my form submission like following:

$(document).ready(function() {
   $("#my_form").submit(function(e) {
         ...
         ...
   }
}

As you see above, it is in $(document).ready(...). When user press "Submit" button on UI, the form will be submitted.

But, How can I also trigger this form submission in Javascript besides user input (e.g. press submit button on UI)?

3 Answers 3

3

Call the submit() DOCs method on the form.

$("#my_form").submit();
Sign up to request clarification or add additional context in comments.

Comments

1

You can use $("#my_form").submit();

Comments

1
 $(document).ready(function () {
        $("#SubmitForm").click(function (e) {
            var textContent = $("#TextContent").val();
            textContent = jQuery.trim(textContent);
            if (textContent == "") {
                alert("Content field cannot be empty.");
                $("#TextContent").focus();
                return false;
            }
            else{ $("#my_form").submit();
            }
        });
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.