I am creating a calculator and need to append numbers by clicking on a div button, instead of typing on the keyboard. But it must integrate with the use of the keyboard. Now, I know how to manipulate strings to achieve this, but positioning the blinking cursor at the end of the input element line escapes me...
Is there a way to call a keyboard event directly via a function call to emulate the key strokes, so that there is no manipulation of strings?
HTML input display markup...
<div id="displayWindow" align="right">
<input id="textInput" type="text" align-"right" value=""></input>
</div>
And here is where I parse the incoming mouse event data:
function keyData(ev){
var kee = ev.target.innerHTML;
var nums = ".1234567890";
if (nums.indexOf(kee)>=0){
//Append value to number input display
// THIS IS WHERE I NEED HELP ....
}
var mathOps = "-+÷×±";
if (mathOps.indexOf(kee)>=0){
//Prepare math operations
}
var chars = "MC M+ M- MR";
if (chars.indexOf(kee)>=0){
//MEMORY handling functions
}
if (kee=="="){
//Calculate
}
if (kee=="C"){
//CLEAR everything
}
}
Any help would be appreciated...
TIA
DK
kee.indexOf(nums,kee) >= 0
– Oliboy50 Jul 6 '14 at 23:55kee
is supposed to be a number (from the use of theindexOf(nums,kee)
, but in your code we can see thisif(kee=="=")
, so what is it? your code is confusing on the thing you want to do. – King King Jul 7 '14 at 0:05