Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>submit event</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> </head> <body> <form id="f"> <input id="name" name="name" placeholder="Name"> <button type="submit">Submit</button> </form> <div id="out"></div> <script> $("#f").on("submit", function(e){ e.preventDefault(); $("#out").text("Submitted: " + $("#name").val()); }); </script> </body> </html>
Output