Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <input type="text" id="calc">
  <button id="calculate">Calculate</button>
</body>
</html>
 
/*jshint laxcomma:true */
var input = document.querySelector('#calc')
  , button = document.querySelector('#calculate');
input.addEventListener('keypress', function(e) {
  var key = String.fromCharCode(e.which);
  if (!/[0-9+\-/*]+/.test(key)) e.preventDefault();
});
  
button.addEventListener('click', function() {
  alert(input.value +' = '+ eval(input.value));
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
elclanrspro
0viewers