Last active
July 8, 2018 22:51
-
-
Save techslides/ba0cfed9e6aad0627022 to your computer and use it in GitHub Desktop.
Form with Client-Side JS
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 lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Form Calculator Add Example</title> | |
</head> | |
<body> | |
<form name="myForm" action="" onsubmit="return calc(this['A'].value,this['B'].value);" method="post"> | |
<input type="text" name="A"> + | |
<input type="text" name="B"> = | |
<span id="result"></span> | |
<br> | |
<input type="submit" value="Submit"> | |
</form> | |
<script> | |
function calc(a,b){ | |
//var a = document.forms["myForm"]["A"].value; | |
//var b = document.forms["myForm"]["B"].value; | |
document.querySelector("#result").textContent = Number(a)+Number(b); | |
return false; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment