Last active
August 29, 2015 14:11
-
-
Save AndrewStanton94/46ebf1e77dd614a8b254 to your computer and use it in GitHub Desktop.
Form with js submit eventListener that overrides default behaviour.
Without preventDefault the form values are added to URL.
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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<title>Dynasite 2c</title> | |
<meta charset = 'UTF-8'> | |
<link rel="icon" href="favicon.ico"> | |
<script src='ds2c.js'></script> | |
<style> | |
fieldset {border-radius: 5px} | |
</style> | |
</head> | |
<body> | |
<h1>ds2c – an active form</h1> | |
<fieldset> | |
<legend>Personal Data</legend> | |
<form id=myfirstform> | |
Name: <input type=text name=who value='Fred Bloggs'> | |
<br> | |
Gender | |
<input type=radio name=gender value=m> M | |
<input type=radio name=gender value=f> F | |
</form> | |
</fieldset> | |
</body> | |
</html> |
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
window.addEventListener( | |
'load', | |
function (event) | |
{ | |
var firstform = document.getElementById('myfirstform'); | |
firstform.addEventListener( | |
'submit', | |
function (event) | |
{ | |
alert('submit'); event.preventDefault(); | |
} | |
); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment