home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / calc.js < prev    next >
Encoding:
JavaScript  |  2004-07-12  |  1.6 KB  |  59 lines

  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. *     http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. var a, b, op;
  17.  
  18. function calculator()
  19. {
  20.   a = getNumber("a");
  21.   b = getNumber("b", a);
  22.   op = getOperator(a, b);
  23.  
  24.   if (op == "plus")
  25.     sendResult(a, b, op, a + b);
  26.   else if (op == "minus")
  27.     sendResult(a, b, op, a - b);
  28.   else if (op == "multiply")
  29.     sendResult(a, b, op, a * b);
  30.   else if (op == "divide")
  31.     sendResult(a, b, op, a / b);
  32.   else
  33.     sendResult("Error: Unkown operator!");
  34. }
  35.  
  36. function getNumber(name, a, b)
  37. {
  38.   var uri = "page/getNumber" + name.toUpperCase();
  39.   cocoon.sendPageAndWait(uri, { "a" : a, "b" : b });
  40.   print(cocoon.request);
  41.   for (i in cocoon.request) {
  42.     print(i + " = " + cocoon.request[i]);
  43.   }
  44.   return parseFloat(cocoon.request.getParameter(name));
  45. }
  46.  
  47. function getOperator(a, b)
  48. {
  49.   cocoon.sendPageAndWait("page/getOperator", { "a" : a, "b" : b });
  50.   return cocoon.request.getParameter("operator");
  51. }
  52.  
  53. function sendResult(a, b, op, result)
  54. {
  55.   cocoon.sendPage("page/displayResult",
  56.            { "a" : a, "b" : b, "operator" : op, "result" : result });
  57. }
  58.  
  59.