Skip to content

Instantly share code, notes, and snippets.

@yusk90
Last active August 29, 2015 14:22
addEventListener
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
#inputField {
width: 94px;
margin-bottom: 5px;
}
</style>
<script type="text/javascript">
window.onload = function (e) {
var form = document.querySelectorAll('div')[0],
inputField = document.getElementById('inputField');
form.addEventListener('click', function (e) {
if (e.target.value) {
inputField.value += e.target.value;
}
});
}
</script>
</head>
<body>
<div>
<input id="inputField" type="text">
<br />
<input type="button" value="1">
<input type="button" value="2">
<input type="button" value="3">
<br />
<input type="button" value="4">
<input type="button" value="5">
<input type="button" value="6">
<br />
<input type="button" value="7">
<input type="button" value="8">
<input type="button" value="9">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment