Created
March 22, 2011 13:02
-
-
Save guyht/881177 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form id="my-form"> | |
<input type="text" name="in" value="some data" /> | |
<button type="submit">Go</button> | |
</form> | |
<script> | |
// Should only be triggered on first page load | |
alert('ho'); | |
function processForm() { | |
/* do what you want with the form */ | |
// Should be triggered on form submit | |
alert('hi'); | |
// You must return false to prevent the default form behavior | |
return false; | |
} | |
var form = document.getElementById('my-form'); | |
if (form.attachEvent) { | |
form.attachEvent("submit", processForm); | |
} else { | |
form.addEventListener("submit", processForm); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment