Posted By

nofuseto on 08/27/09


Tagged

Calculator


Versions (?)

Simple Javascript Calculator


 / Published in: JavaScript
 

  1. <form name="Calc">
  2. <table>
  3. <tr>
  4. <td colspan="4"><input type="text" name="Input" size="16"></td>
  5. </tr>
  6. <tr>
  7. <td><input type="button" name="one" value=" 1 " onClick="Calc.Input.value += '1'"></td>
  8. <td><input type="button" name="two" value=" 2 " onClick="Calc.Input.value += '2'"></td>
  9. <td><input type="button" name="three" value=" 3 " onClick="Calc.Input.value += '3'"></td>
  10. <td><input type="button" name="plus" value=" + " onClick="Calc.Input.value += ' + '"></td>
  11. </tr>
  12. <tr>
  13. <td><input type="button" name="four" value=" 4 " onClick="Calc.Input.value += '4'"></td>
  14. <td><input type="button" name="five" value=" 5 " onClick="Calc.Input.value += '5'"></td>
  15. <td><input type="button" name="six" value=" 6 " onClick="Calc.Input.value += '6'"></td>
  16. <td><input type="button" name="minus" value=" - " onClick="Calc.Input.value += ' - '"></td>
  17. </tr>
  18. <tr>
  19. <td><input type="button" name="seven" value=" 7 " onClick="Calc.Input.value += '7'"></td>
  20. <td><input type="button" name="eight" value=" 8 " onClick="Calc.Input.value += '8'"></td>
  21. <td><input type="button" name="nine" value=" 9 " onClick="Calc.Input.value += '9'"></td>
  22. <td><input type="button" name="times" value=" x " onClick="Calc.Input.value += ' * '"></td>
  23. </tr>
  24. <tr>
  25. <td><input type="button" name="clear" value=" CE " onClick="Calc.Input.value = ''"></td>
  26. <td><input type="button" name="zero" value=" 0 " onClick="Calc.Input.value += '0'"></td>
  27. <td><input type="button" name="comma" value=" , " onClick="Calc.Input.value += '.'"></td>
  28. <td><input type="button" name="div" value=" / " onClick="Calc.Input.value += ' / '"></td>
  29. </tr>
  30. <tr>
  31. <td colspan="3"><input type="button" name="DoIt" value=" TOTALE " onClick="Calc.Input.value = eval(Calc.Input.value).toFixed(2)"></td>
  32. <td></td>
  33. </tr>
  34. </table>
  35. </form>

Report this snippet  

You need to login to post a comment.