Skip to content

Instantly share code, notes, and snippets.

@ericanderson

ericanderson/README.md

Last active Dec 21, 2015
Embed
What would you like to do?
Many ways to submit a form...

This gist demonstrates that you need a lot of special handlers for form submission...

$ ->
$('#form2').submit (e) ->
alert('on submit')
e.preventDefault()
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title></title>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/coffee-script/1.6.3/coffee-script.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/coffeescript" src="code.coffee"></script>
</head>
<body>
<h1>No event handlers</h1>
<p>Try pressing enter in this textbox...</p>
<form id="form1">
<input type="text" name="foo">
<button>Submit</button>
</form>
<h1>Form w/ submit handler + preventDefault()</h1>
<form id="form2">
<input type="text" name="foo">
<button>Submit</button>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment