Posted by Eric on 10/02/05 20:07
I have a little html calculator form that I've been playing with, you click
the buttons to enter data and operators. I wanted to add the ability to
also press keys instead of only being able to click on buttons.
here's a portion of what i have.
<div style="text-align:center">
<input id="display" style="width:120;text-align:right" readonly>
<br>
<input type="button" value=" 1 " onClick="display.value += '1'">
<input type="button" value=" 2 " onClick="display.value += '2'">
<input type="button" value=" 3 " onClick="display.value += '3'">
etc etc
<input type="button" value=" . " onClick="display.value += '.'">
<input type="button" value=" C " onClick="display.value = ''">
<br>
<input type="button" value=" x " onClick="display.value += ' x '">
<input type="button" value=" / " onClick="display.value += ' / '">
<input type="button" value=" - " onClick="display.value += ' - '">
<input type="button" value=" + " onClick="display.value += ' + '">
<br>
<input type="button" value=" sqrt " onClick="display.value =
Math.sqrt(display.value)">
<input type="button" value=" = " onClick="display.value =
eval(display.value)">
</div>
How do i add the onKeyPress so that both clicking and typing work?
Thanks
Eric
Navigation:
[Reply to this message]
|