home *** CD-ROM | disk | FTP | other *** search
/ Magazyn WWW 1999 July / www_07_1999.iso / prez / amiga / KidHTML1_25.lha / KidHTML1.25 / Script / calculator.js < prev    next >
Text File  |  1998-08-25  |  2KB  |  67 lines

  1. <!-- TWO STEPS TO INSTALL 5 FUNCTION CALCULATOR:
  2.  
  3.    1.  Paste the coding into the HEAD of your HTML document
  4.    2.  Add the last code into the BODY of your HTML document  -->
  5.  
  6. <!-- STEP ONE: Copy this code into the HEAD of your HTML document  -->
  7.  
  8. <HEAD>
  9.  
  10. <SCRIPT LANGUAGE="JavaScript">
  11.  
  12. <!-- Original: Rick Johnson -->
  13. <!-- Web Site:  http://members.tripod.com/~RickJohnson -->
  14.  
  15. <!-- This script and many more are available online from -->
  16. <!-- The JavaScript Source!! http://javascriptsource.com -->
  17.  
  18. <!-- Begin
  19. function a_plus_b(form) {
  20. a=eval(form.a.value)
  21. b=eval(form.b.value)
  22. c=a+b
  23. form.ans.value = c
  24. }
  25. function a_minus_b(form) {
  26. a=eval(form.a.value)
  27. b=eval(form.b.value)
  28. c=a-b
  29. form.ans.value=c
  30. }
  31. function a_times_b(form) {
  32. a=eval(form.a.value)
  33. b=eval(form.b.value)
  34. c=a*b
  35. form.ans.value=c
  36. }
  37. function a_div_b(form) {
  38. a=eval(form.a.value)
  39. b=eval(form.b.value)
  40. c=a/b
  41. form.ans.value = c
  42. }
  43. function a_pow_b(form) {
  44. a=eval(form.a.value)
  45. b=eval(form.b.value)
  46. c=Math.pow(a, b)
  47. form.ans.value = c
  48. }
  49. // End -->
  50. </SCRIPT>
  51.  
  52. <!-- STEP TWO: Put this code into the BODY of your HTML document  -->
  53.  
  54. <BODY>
  55. <CENTER>
  56. <FORM name="formx"><input type=text size=4 value=12 name="a"> 
  57. <input type="button" value="  +  " onClick="a_plus_b(this.form)">áá
  58. <input type="button" value="  -  " onClick="a_minus_b(this.form)">áá
  59. <input type="button" value="  x  " onClick="a_times_b(this.form)">áá
  60. <input type="button" value="  /  " onClick="a_div_b(this.form)">áá
  61. <input type="button" value="  ^  " onClick="a_pow_b(this.form)">áá
  62. <input type="number" size=4 value=3 name="b"> = <input type "number" value=0 name="ans" size=9>
  63. </FORM>
  64. </CENTER>
  65.  
  66. <!-- Script Size:  1.72 KB  -->
  67.