home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 February / PCWorld_2000-02_cd.bin / Komunik / Webscr / HTMLtool / _SETUP.1 / Calculator.scp < prev    next >
Text File  |  1999-10-03  |  4KB  |  118 lines

  1. <HTMLtool>A nice calculator</HTMLtool>
  2. <table border="2" width="200" cellspacing="0" cellpadding="0" bgcolor="#000000"
  3. style="border-color:black" onClick="previouskey=event.srcElement.innerText">
  4.   <tr>
  5.     <td width="100%" bgcolor="#FFFFFF" id="result"
  6.     style="font:bold 20px Verdana;color:black;text-align='right'">0</td>
  7.   </tr>
  8.   <tr>
  9.     <td width="100%" valign="middle" align="center"><table border="0" width="100%"
  10.     cellspacing="0" cellpadding="0" style="font:bold 20px Verdana;color:white">
  11.       <tr>
  12.         <td width="80%" align="center"><table border="1" width="100%" cellspacing="0"
  13.         cellpadding="0" style="cursor:hand;font:bold 20px Verdana;color:white"
  14.         onMouseover="if (event.srcElement.tagName=='TD')event.srcElement.style.color='yellow'"
  15.         onMouseout="event.srcElement.style.color='white'" onselectStart="return false"
  16.         onClick="calculate()" height="82">
  17.           <tr>
  18.             <td width="25%" align="center" height="17">7</td>
  19.             <td width="25%" align="center" height="17">8</td>
  20.             <td width="25%" align="center" height="17">9</td>
  21.             <td width="25%" align="center" height="17">/</td>
  22.           </tr>
  23.           <tr>
  24.             <td width="25%" align="center" height="19">4</td>
  25.             <td width="25%" align="center" height="19">5</td>
  26.             <td width="25%" align="center" height="19">6</td>
  27.             <td width="25%" align="center" height="19">*</td>
  28.           </tr>
  29.           <tr>
  30.             <td width="25%" align="center" height="19">1</td>
  31.             <td width="25%" align="center" height="19">2</td>
  32.             <td width="25%" align="center" height="19">3</td>
  33.             <td width="25%" align="center" height="19">-</td>
  34.           </tr>
  35.           <tr>
  36.             <td width="25%" align="center" height="19">0</td>
  37.             <td width="25%" align="center" height="19"
  38.             onClick="pn();previouskey=1;event.cancelBubble=true">+/-</td>
  39.             <td width="25%" align="center" height="19">.</td>
  40.             <td width="25%" align="center" height="19">+</td>
  41.           </tr>
  42.         </table>
  43.         </td>
  44.         <td width="20%"><div align="left"><table border="1" width="100%" cellspacing="0"
  45.         cellpadding="0">
  46.           <tr>
  47.             <td width="100%" style="cursor:hand;font:bold 20px Verdana;color:white;text-align:center"
  48.             onClick="result.innerText=0;results=''">C</td>
  49.           </tr>
  50.         </table>
  51.         </div><div align="left"><table border="1" width="100%" cellspacing="0" cellpadding="0"
  52.         height="81">
  53.           <tr>
  54.             <td width="100%" style="cursor:hand;font:bold 32px Verdana;color:white;text-align:center"
  55.             onMouseover="event.srcElement.style.color='yellow'"
  56.             onMouseout="event.srcElement.style.color='white'" onClick="calculateresult()">=</td>
  57.           </tr>
  58.         </table>
  59.         </div></td>
  60.       </tr>
  61.     </table>
  62.     </td>
  63.   </tr>
  64. </table>
  65. <script language="JavaScript1.2">
  66. var results=''
  67. var previouskey=''
  68. var re=/(\/|\*|\+|-)/
  69. var re2=/(\/|\*|\+|-){2}$/
  70. var re3=/.+(\/|\*|\+|-).+/
  71. var re4=/\d|\./
  72. var re5=/^[^\/\*\+].+\d$/
  73. var re6=/\./
  74.  
  75. function calculate(){
  76. if (event.srcElement.tagName=="TD"){
  77. if (event.srcElement.innerText.match(re4)&&previouskey=="=")
  78. results=''
  79. if (result.innerText.match(re3)&&event.srcElement.innerText.match(re)){
  80. if (!results.match(re5)){
  81. result.innerText="Error!"
  82. return
  83. }
  84. results=eval(results)
  85. if (results.toString().length>=12&&results.toString().match(re6))
  86. results=results.toString().substring(0,12)
  87. result.innerText=results
  88. }
  89.  
  90. results+=event.srcElement.innerText
  91. if (results.match(re2))
  92. results=results.substring(0,results.length-2)+results.charAt(results.length-1)
  93.  
  94. result.innerText=results
  95. }
  96. }
  97.  
  98. function calculateresult(){
  99. if (!results.match(re5)){
  100. result.innerText="Error!"
  101. return
  102. }
  103. results=eval(results)
  104. if (results.toString().length>=12&&results.toString().match(re6))
  105. results=results.toString().substring(0,12)
  106. result.innerText=results
  107. }
  108.  
  109.  
  110.  
  111. function pn(){
  112. if (result.innerText.charAt(0)!='-')
  113. result.innerText=results='-'+result.innerText
  114. else if (result.innerText.charAt(0)=='-')
  115. result.innerText=results=result.innerText*(-1)
  116. }
  117.  
  118. </script>