Skip to content

Commit

Permalink
onkeyup allowedChar update
Browse files Browse the repository at this point in the history
  • Loading branch information
rhalp10 committed Sep 27, 2017
1 parent 228b239 commit b908d6f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h1 class="display-3">Simple Calculator</h1>
<div class="info-form">
<form action="" class="form-inline justify-content-center" name="calc">

<input type="" name="" class="form-control col-sm-12" id="input_text" onkeyup="allowedChar(this);">
<input type="" name="" class="form-control col-sm-12" id="input_text" onkeyup="allowedChar(this);" >
<div class="col-sm-10 ">
<hr>
<div class="text-center select_button">
Expand Down Expand Up @@ -113,7 +113,14 @@ <h1 class="display-3">Simple Calculator</h1>
function answerText()
{
//easiest code "eval()"
document.calc.input_text.value = eval(document.calc.input_text.value);

try {
document.calc.input_text.value = eval(document.calc.input_text.value);;
} catch (e) {
if (e instanceof SyntaxError) {
alert(e.message);
}
}
// var a = parseInt("10");
// var b = parseInt("10");
// var c = a+b;
Expand All @@ -137,7 +144,7 @@ <h1 class="display-3">Simple Calculator</h1>
}
//NUMBER ONLY
function allowedChar(elem) {
var validChars = /[0-9().%^+-*/]/;
var validChars = /[0-9(). ]/;
var strIn = elem.value;
var strOut = '';
for(var i=0; i < strIn.length; i++) {
Expand Down

0 comments on commit b908d6f

Please sign in to comment.