Skip to content

Instantly share code, notes, and snippets.

@chikoski
Created April 24, 2013 03:06
Show Gist options
  • Save chikoski/5449290 to your computer and use it in GitHub Desktop.
Save chikoski/5449290 to your computer and use it in GitHub Desktop.
input{
display: inline;
}
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>計算機</title>
</head>
<body>
<form>
<input type="text" size="5" id="a"> +
<input type="text" size="5" id="b"> =
<input type="text" size="5" id="c">
</form>
</body>
</html>
var calc = function(e){
var input_a = document.getElementById("a");
var input_b = document.getElementById("b");
var input_c = document.getElementById("c");
var a = Number(input_a.value);
var b = Number(input_b.value);
var c = a + b;
input_c.value = c;
};
var input_a = document.getElementById("a");
var input_b = document.getElementById("b");
input_a.onchange = calc;
input_b.onchange = calc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment