Skip to content

Instantly share code, notes, and snippets.

@techslides
Last active July 8, 2018 22:51
Show Gist options
  • Save techslides/ba0cfed9e6aad0627022 to your computer and use it in GitHub Desktop.
Save techslides/ba0cfed9e6aad0627022 to your computer and use it in GitHub Desktop.
Form with Client-Side JS
<!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