Created
July 20, 2013 18:51
-
-
Save mattneary/6046057 to your computer and use it in GitHub Desktop.
SO Adder
This file contains hidden or 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
<script> | |
var inputs = {}; | |
function save(value, name) { | |
inputs[name] = parseInt(value); | |
} | |
function checker(criterion, action) { | |
return function(value, name) { | |
if( !criterion(value) ) { | |
alert("Not Numeric"); | |
} else { | |
action(value, name); | |
} | |
}; | |
} | |
function isNumber(x) { | |
return !isNaN(x); | |
} | |
function addFunction(elm) { | |
elm.value = inputs.num1 + inputs.num2; | |
} | |
</script> | |
<input id="num1" type="text" onblur="checker(isNumber, save)(this.value, 'num1')">+ | |
<input id="num2" type="text" onblur="checker(isNumber, save)(this.value, 'num2')"> = <input id="adds" type="text" onfocus="addFunction(this)"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment