Last active
August 29, 2015 14:11
-
-
Save AndrewStanton94/a67029360b6f0241239c to your computer and use it in GitHub Desktop.
Takes values from form and displays them onscreen.
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 2d</title> | |
<meta charset = 'UTF-8'> | |
<link rel="icon" href="favicon.ico"> | |
<script src='ds2d.js'></script> | |
<style> | |
fieldset {border-radius: 5px} | |
</style> | |
</head> | |
<body> | |
<h1>ds2d – a revised 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> | |
<div id=fieldstuff></div> | |
<div id=radiostuff></div> | |
</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
function getFormRadioValue (formelem, radioname) { | |
var buttons = formelem[radioname]; | |
for (var i=0, n=buttons.length; i<n; i++) | |
if (buttons[i].checked) | |
return buttons[i].value; | |
return undefined; | |
} | |
function movestuff () { | |
var theform = document.getElementById('myfirstform'); | |
var fielddiv = document.getElementById('fieldstuff'); | |
var radiodiv = document.getElementById('radiostuff'); | |
fielddiv.innerHTML = '<p>Text field value is "' + theform.who.value + '" </p>'; | |
radiodiv.innerHTML = '<p>Radio-button value is "' + getFormRadioValue(theform, 'gender') + '" </p>'; | |
} | |
window.addEventListener( | |
'load', | |
function (event) | |
{ | |
var firstform = document.getElementById('myfirstform'); | |
firstform.addEventListener( | |
'submit', | |
function (event) | |
{ | |
movestuff(); | |
event.preventDefault(); | |
} | |
); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment