Reputation: 63
I am trying to make a calculator using phonegap - but I am running into problems in adding the touch event. It does not show anything on the display. kindly see if there are problems in the code. and suggest me a solution.
**I have added the onTouch
event to all the numbers and math operators buttons.
function onload(){
document.getElementById("display").addEventListener('onTouch',insert,false);
document.getElementById("clear").addEventListener('onClear', clear, false);
document.getElementById("equal")addEventListener('onEqual', evaluate,false);
}
function clear(){
document.getElementById("display").value="";
return false;
}
function insert(val){
document.getElementById("display").value+=val;
}
function evaluate(){
try
{
ans= eval(document.getElementById("display").value);
document.getElementById("display")=ans;
return false;
}
catch
{
document.getElementById("display").value="Error";
return false;
}
}
Upvotes: 0
Views: 278
Reputation: 4742
I am not sure about the onTouch
event. Does that exist at all?
I would suggest to try either touchstart
or touchend
maybe touchmove
event handlers. These should work. For example:
document.getElementById("display").addEventListener('touchstart',insert,false);
Upvotes: 2