How to add, subtract, multiply two numbers from a single input box?
e.g.: have input text box
<input type = "text" id = "id">
I need to add, subtract, multiply two numbers using the single text box. I have separate buttons for add, sub and multiply.
I have tried something like this:
var te = 0;
var input = false;
function number(value){
if(input === false){
document.getElementById("id").value += value;
}else{
document.getElementById("id").value = value;
input = false;
}
};
function calc(opr){
if(opr === '+'){
te=te+parseInt(document.getElementById("id").value);
document.getElementById("id").value = te;
input = true;
}
};
Addition is working fine. I need to add multiplication, subtraction and equal to to this.