English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The Submit() method triggers the Submit event, or attach a function to be executed when the Submit event occurs.
The Submit event occurs when the form is submitted.
Note:This event can only be used on <form> elements.
Trigger the Submit event of the selected element:
$(selector).submit()
Attach a function to the Submit event:
$(selector).submit(function)
When submitting the form, a reminder message is displayed:
$("form").submit(function() { alert("Submit() handler called"); });Test and see‹/›
Prevent form submission unless the condition is met:
$("form").submit(function(event) { if($("input:first").val() === "Alpha") { return true; } $("span").text("Invalid!").show().fadeOut(1000); event.preventDefault(); });Test and see‹/›
Prevent form submission unless the condition is met:
$("form").submit(function(event) { if($("input:first").val().length >= 10) { alert("Good"); } else { alert("Need10or more characters"); $("input:first").css("outline", "");1px solid red"); event.preventDefault(); } });Test and see‹/›
Parameters | Description |
---|---|
function | Function executed each time an event is triggered |