Calculator in javascript

26 views

  1. <script type="text/javascript">function result()
  2. {
  3. try{
  4. document.form1.Input.value=eval(form1.Input.value);
  5. }
  6. catch(e){
  7. alert(‘oops! wrong use of operators’);
  8. }
  9. }</script>
  10. <form>
  11. <table border="4">
  12. <tbody>
  13. <tr>
  14. <td>
  15. <input name="Input" size="16" type="text" /></td>
  16. </tr>
  17. <tr>
  18. <td>
  19. <input onclick="form1.Input.value += ‘1′" name="one" type="button" value="  1  " />
  20. <input onclick="form1.Input.value += ‘2′" name="two" type="button" value="  2  " />
  21. <input onclick="form1.Input.value += ‘3′" name="three" type="button" value="  3  " />
  22. <input onclick="form1.Input.value += ‘ + ‘" name="plus" type="button" value="  +  " />
  23.  
  24. <input onclick="form1.Input.value += ‘4′" name="four" type="button" value="  4  " />
  25. <input onclick="form1.Input.value += ‘5′" name="five" type="button" value="  5  " />
  26. <input onclick="form1.Input.value += ‘6′" name="six" type="button" value="  6  " />
  27. <input onclick="form1.Input.value += ‘ - ‘" name="minus" type="button" value="  -  " />
  28.  
  29. <input onclick="form1.Input.value += ‘7′" name="seven" type="button" value="  7  " />
  30. <input onclick="form1.Input.value += ‘8′" name="eight" type="button" value="  8  " />
  31. <input onclick="form1.Input.value += ‘9′" name="nine" type="button" value="  9  " />
  32. <input onclick="form1.Input.value += ‘ * ‘" name="times" type="button" value="  x  " />
  33.  
  34. <input onclick="form1.Input.value = ”" name="clear" type="button" value="  c  " />
  35. <input onclick="form1.Input.value += ‘0′" name="zero" type="button" value="  0  " />
  36. <input onclick="result()" name="DoIt" type="button" value="  =  " />
  37. <input onclick="form1.Input.value += ‘ / ‘" name="div" type="button" value="  /  " /></td>
  38. </tr>
  39. </tbody></table>
  40. </form>



« IE8 creating problem with callback function (jQuery Or Javascript) How To Disable Form Tag or Element In javascript »
Posted on Tuesday, April 7th, 2009 at 2:32 pm under Javascript | RSS 2.0 Feed

Post Comment

You must be logged in to post a comment.



ComputerEducationWorld.com All Rights Reserved © RSS | CBSE | Education Boards Of India | What is My IP?