Skip to content

Instantly share code, notes, and snippets.

@theptrk
Created May 17, 2020 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theptrk/576fe3b5907104c4ca5dec619ea1c77f to your computer and use it in GitHub Desktop.
Save theptrk/576fe3b5907104c4ca5dec619ea1c77f to your computer and use it in GitHub Desktop.
HTML onsubmit connected to javascript function using a todo list input example
<!DOCTYPE html>
<html>
<head>
<title>Hello onsubmit</title>
</head>
<body>
<h1>Hello onsubmit</h1>
<form onsubmit="handleForm()">
<input type="text" name="todo" autocomplete="off">
<button type="submit">Create Todo</button>
</form>
<script type="text/javascript">
function handleForm(e) {
console.log(e)
}
</script>
</body>
</html>
@theptrk
Copy link
Author

theptrk commented May 17, 2020

This needs a prevent default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment