home *** CD-ROM | disk | FTP | other *** search
/ PC User 2005 May / CD / PCU0505CD.iso / software / full / coffecup / files / html2005.exe / %MAINDIR% / Javascript / Calculator-5function.xml < prev    next >
Encoding:
Text File  |  2005-02-16  |  1.8 KB  |  79 lines

  1. <ccResource>
  2.   <ccTitle>
  3. Calculator with 5 Functions
  4.   </ccTitle>
  5.   <ccCategory>
  6. Calculators
  7.   </ccCategory>
  8.   <ccDescription>
  9. Here is a really simple JavaScript calculator - with just 5 functions! (Add, subtract, multiply, divide, and power)
  10.   </ccDescription>
  11.   <ccInstructions>
  12.    1.  Paste the coding into the HEAD of your HTML document
  13.    2.  Add the last code into the BODY of your HTML document
  14.   </ccInstructions>
  15.   <ccHeadContent>
  16.   
  17.   </ccHeadContent>
  18.   <ccBodyContent>
  19. <SCRIPT LANGUAGE="JavaScript">
  20.  
  21. <!-- Begin
  22. function a_plus_b(form) {
  23. a=eval(form.a.value)
  24. b=eval(form.b.value)
  25. c=a+b
  26. form.ans.value = c
  27. }
  28. function a_minus_b(form) {
  29. a=eval(form.a.value)
  30. b=eval(form.b.value)
  31. c=a-b
  32. form.ans.value=c
  33. }
  34. function a_times_b(form) {
  35. a=eval(form.a.value)
  36. b=eval(form.b.value)
  37. c=a*b
  38. form.ans.value=c
  39. }
  40. function a_div_b(form) {
  41. a=eval(form.a.value)
  42. b=eval(form.b.value)
  43. c=a/b
  44. form.ans.value = c
  45. }
  46. function a_pow_b(form) {
  47. a=eval(form.a.value)
  48. b=eval(form.b.value)
  49. c=Math.pow(a, b)
  50. form.ans.value = c
  51. }
  52. // End -->
  53. </SCRIPT>
  54.  
  55. <!-- STEP TWO: Put this code into the BODY of your HTML document  -->
  56.  
  57. <CENTER>
  58. <FORM name="formx"><input type=text size=4 value=12 name="a"> 
  59. <input type="button" value="  +  " onClick="a_plus_b(this.form)">  
  60. <input type="button" value="  -  " onClick="a_minus_b(this.form)">  
  61. <input type="button" value="  x  " onClick="a_times_b(this.form)">  
  62. <input type="button" value="  /  " onClick="a_div_b(this.form)">  
  63. <input type="button" value="  ^  " onClick="a_pow_b(this.form)">  
  64. <input type="number" size=4 value=3 name="b"> = <input type "number" value=0 name="ans" size=9>
  65. </FORM>
  66. </CENTER>
  67.  
  68.  
  69.   </ccBodyContent>
  70.   <ccElementContent>
  71.   
  72.    <ccElementName></ccElementName>
  73.    <ccElementAction></ccElementAction>
  74.    
  75.   </ccElementContent>
  76.   <ccExtraData>
  77.  
  78.   </ccExtraData>
  79. </ccResource>