Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

September 27, 2022, 02:33:14 PM

Login with username, password and session length
Members
Stats
  • Total Posts: 193513
  • Total Topics: 21092
  • Online today: 68
  • Online ever: 3540
  • (September 02, 2022, 06:38:54 PM)
Users Online
Users: 1
Guests: 52
Total: 53

Author Topic: A calculator on a script/html block, may be ?  (Read 8118 times)

0 Members and 1 Guest are viewing this topic.

elpvn

  • Guest
A calculator on a script/html block, may be ?
« on: May 18, 2006, 07:35:30 AM »
Try this co
Code: [Select]
<SCRIPT>

LastOper     = '';

TempVal      = 0;

NewNum       = 'Y';

Memval       = 0;

Dotused      = "N";

Curroption   = 4;

Maxoption    = 19;

FirstinXonY  = '';

Statelements = [0];

n            = 0;

Ave          = 0;

Max          = 1.1111111234;

Min          = 1.1111111234;

Dummymaxmin  = 1.1111111234;

Sum          = 0;

additionalfunctions = ["x^2", "2^x", "x^y", "x^3", " n!  ", "Log", " Pi ", " h ", "Tan", "Cot", "Sin", "Cos", "Add", "Sum", "Ave", "Max", "Min", " n ", "Clr St", "Sta"]; 

function backspace()

{

  strlen = document.calc.Results.value.length;

  if (strlen > 1 && document.calc.Results.value != "0."){document.calc.Results.value =  document.calc.Results.value.substring(0,strlen-1);}

  document.calc.EQ.focus();

}

function Onediv()

{

  if (document.calc.Results.value == '0.')

  {

    document.calc.Results.value = "Can't Devide By 0";

  }

  else

  {

    document.calc.Results.value = 1 / document.calc.Results.value;

    NewNum = "Y";

  }

  document.calc.EQ.focus();

}

function MoreOptions()

{

  if (Curroption > Maxoption) {Curroption = 0;}

  document.calc.opt1.value = additionalfunctions[Curroption++];

  if (Curroption > Maxoption) {Curroption = 0;}

  document.calc.opt2.value = additionalfunctions[Curroption++];

  if (Curroption > Maxoption) {Curroption = 0;}

  document.calc.opt3.value = additionalfunctions[Curroption++];

  if (Curroption > Maxoption) {Curroption = 0;}

  document.calc.opt4.value = additionalfunctions[Curroption++];

  document.calc.EQ.focus();

}

function Advfunction(Pos)

{

  Pos += Curroption;

  Pos -= 4;

  if (Pos < 0) {Pos = Maxoption + Pos;}

  if (Pos == 0) {document.calc.Results.value *= document.calc.Results.value;}

  if (Pos == 1) {

                  Temp = 1;

                  for (var I = 0 ;I < document.calc.Results.value; I++)

                  {

                   Temp *= 2;

                  }

                  document.calc.Results.value = Temp;

                }

  if (Pos == 2)  {

                  if (FirstinXonY == '')

                  {

                    FirstinXonY = document.calc.Results.value;

                  }

                  else

                  {

                    Temp = FirstinXonY;

                    for (var I = 1 ;I < document.calc.Results.value; I++)

                    {

                     Temp *= FirstinXonY;

                    }

                    document.calc.Results.value = Temp;

                    FirstinXonY = '';

                  }

                }

   if (Pos == 4){Temp = 0; for (var I = 1; I <= document.calc.Results.value;I++) {Temp += I} document.calc.Results.value = Temp;}

   if (Pos == 6){document.calc.Results.value =  3.14159265359;}           

   if (Pos == 12)

                {

                 Statelements[++n] = document.calc.Results.value;

                 Expres = "Sum = + +" + Sum + " + " + "+" + document.calc.Results.value;

                 eval(Expres);

                 Ave = Sum/n;

                 Max = 1 * Max;

                 Min = 1 * Min;

                 if (Max < document.calc.Results.value || Max == Dummymaxmin) {Max = document.calc.Results.value;}

                 if (Min > document.calc.Results.value || Min == Dummymaxmin) {Min = document.calc.Results.value;} 

                }

   if (Pos == 13){document.calc.Results.value = Sum;}

   if (Pos == 14){document.calc.Results.value = Ave;}

   if (Pos == 15){if (n > 0) {document.calc.Results.value = Max;}}

   if (Pos == 16){if (n > 0) {document.calc.Results.value = Min;}}

   if (Pos == 17){document.calc.Results.value = n;}

   if (Pos == 18)

                {

                 Statelements = [0];

                 n            = 0;

                 Ave          = 0;

                 Max          = 1.1111111234;

                 Min          = 1.1111111234;

                 Dummymaxmin  = 1.1111111234;

                 Sum          = 0;                 

                }

   if (Pos == 19)

                {

                 if (n > 0)

                 {

                   myWindow = window.open("", "newwin", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width=200,height=180,left=400,top=300");

                   myWindow.document.open();

                   myWindow.document.write("<HTML><HEAD>");

                   myWindow.document.write("<TITLE>Statistics</TITLE>");

                   myWindow.document.write("</HEAD><FORM><BODY BGCOLOR=#FFFFFF TEXT=black>\n<CENTER>");

                   myWindow.document.write("<TABLE ALIGN=CENTER>");

                   myWindow.document.write("<TR><TD><B>n</B></TD><TD>: "  , n  , "</TD></TR>");

                   myWindow.document.write("<TR><TD><B>Sum</B></TD><TD>: ", Sum, "</TD></TR>");

                   myWindow.document.write("<TR><TD><B>Ave</B></TD><TD>: ", Ave, "</TD></TR>");

                   myWindow.document.write("<TR><TD><B>Max</B></TD><TD>: ", Max, "</TD></TR>");

                   myWindow.document.write("<TR><TD><B>Min</B></TD><TD>: ", Min, "</TD></TR>");

                   myWindow.document.write("</TABLE>");

                   myWindow.document.write(" <BR><INPUT TYPE='SUBMIT' VALUE='OK' onClick='window.close()'</FORM>\n</CENTER>");

                   myWindow.document.write("</BODY></HTML>");

                   myWindow.document.close();

                 }

                 else

                 {

                   myWindow = window.open("", "newwin", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width=200,height=180,left=400,top=300");

                   myWindow.document.open();

                   myWindow.document.write("<HTML><HEAD>");

                   myWindow.document.write("<TITLE> No Statistics</TITLE>");

                   myWindow.document.write("</HEAD><FORM><BODY BGCOLOR=#FFFFFF TEXT=BLACK>\n<CENTER>");

                   myWindow.document.write("<U><B>No Statistics</B></U><BR><BR>You did not add any item<BR>to the statistics<BR>To add items, use The<BR>'Add' Button");

                   myWindow.document.write("<BR><BR><INPUT TYPE='SUBMIT' VALUE='OK' onClick='window.close()'</FORM></CENTER>");

                   myWindow.document.write("</BODY></HTML>");

                   myWindow.document.close();

                 }

                }

  NewNum = 'Y';

}

     

function SQRT()

{

  document.calc.Results.value = sqrt( document.calc.Results.value);

  NewNum = "Y";

  document.calc.EQ.focus();

}

function Percent()

{

  document.calc.Results.value *= TempVal / 100;

  Dotused = "N";

  NewNum = "Y";

  document.calc.EQ.focus();

}

 

function Oper(OP)

{

  if (LastOper == "+")

  {

     num1 = document.calc.Results.value;

     Command = eval ("'+' + num1 +  '+' + TempVal");

     document.calc.Results.value= eval (Command);

  }

     if (LastOper == "-")

  {

     num1 = document.calc.Results.value;

     Command = "(document.calc.Results.value = TempVal - num1)";

     eval (Command);

  }

  if (LastOper == "*")

  {

     num1 = document.calc.Results.value;

     Command = "(document.calc.Results.value = TempVal * num1)";

     eval (Command);

  }

  if (LastOper == "/")

  {

    if (document.calc.Results.value == '0.')

    {

      document.calc.Results.value = "Can't Devide By 0";

    }

    else

    {

      num1 = document.calc.Results.value;

      Command = "(document.calc.Results.value = TempVal / num1)";

      eval (Command);

    }

  }

 if (OP != "=")

 {

   document.calc.oper.value = " " + OP;

 }

 else

 {

   document.calc.oper.value ="";

 }

 NewNum = "Y";

 LastOper = OP;

 TempVal = document.calc.Results.value ;

 document.calc.EQ.focus();

 FirstinXonY = '';

}

 

function Analyzethis(Key)

{

  if (Key >= "0" && Key <= "9" )

  {

    Digit(Key);

  }

  if (Key == "*" || Key == "-" || Key == "\\" || Key == "+" || Key == "=")

  {

    Oper(Key);

  }

  document.calc.EQ.focus();

}

 

function Memory(Mode)

{

    if (Mode == "Clear")

    {

       document.calc.Mem.value="";

       Memval = 0;     

    }

    if (Mode == "Set")

    {

        document.calc.Mem.value = "M";

        Memval = document.calc.Results.value;

    }

    if (Mode == "Add")

    {

        document.calc.Mem.value = "M";

        Command = eval("'+' + document.calc.Results.value + '+' + Memval");

        Memval = eval (Command);

    }

    if (Mode == "Read")

    {

        document.calc.Results.value = Memval;

        NewNum = "Y";

    }   

    document.calc.EQ.focus();

}

function Dot()

{

  if (NewNum == "Y")

  {

    document.calc.Results.value = "0.";

    Dotused = "Y";

    NewNum = "N";

  }

  if (Dotused == "N")

  {

    document.calc.Results.value += ".";

    Dotused = "Y";

  }           

  document.calc.EQ.focus();

}

 

function Changesign()

{

  document.calc.Results.value *= -1;

  document.calc.EQ.focus();

}

function Digit(DG)

{

  if (NewNum == "Y")

  {

    document.calc.Results.value=DG;

    Dotused = "N";

  }

  else

  {

    document.calc.Results.value= document.calc.Results.value + DG;

  }

 

  if (document.calc.Results.value == '0')

  {

   document.calc.Results.value = '0.'

  }

  else

  {

   NewNum = "N";

  }

  document.calc.EQ.focus();

}

function Clear (Type)

{

  document.calc.Results.value = '0.';

  NewNum = 'Y';

  if (Type == "ALL")

  {

     document.calc.oper.value ="";

     LastOper = '';

     TempVal = 0;

  }

  document.calc.EQ.focus();

}

</SCRIPT>



<TD onLoad="document.calc.EQ.focus()">

<CENTER>

   <FORM NAME=calc>

   <BR>

   <TABLE border=5>

   <TR>

       <TD COLSPAN = 6><INPUT TYPE = Text NAME=Results size=19 VALUE = '0.'  align=right  onFocus="this.blur()" >

                       <INPUT TYPE = text NAME=oper    size=1  VALUE = ''    align=center onFocus="this.blur()"> 

       </TD>

   </TR>

   <TR>

       <TD align=center><INPUT TYPE = TEXT MAXLENGTH=1 SIZE=1 NAME=Mem onFocus="this.blur()"></TD>

       <TD COLSPAN = 2 align=center> <INPUT TYPE=button VALUE='BkSp' onClick="backspace()"></TD>

       <TD COLSPAN = 2 align=center> <INPUT TYPE=button VALUE='  CE ' onClick="Clear('Res')"></TD>

       <TD COLSPAN = 1 align=center> <INPUT TYPE=button VALUE=' C ' onClick="Clear('ALL')"></TD>

   </TR>     

   <TR>

       <TD align=center><INPUT TYPE = button VALUE='MC' onClick="Memory('Clear')"></TD>

       <TD align=center><INPUT TYPE = button VALUE=' 7 ' onClick="Digit(7)" NAME='D7'></TD>

       <TD align=center><INPUT TYPE = button VALUE=' 8 ' onClick="Digit(8)" NAME='D8'></TD>

       <TD align=center><INPUT TYPE = button VALUE=' 9 ' onClick="Digit(9)" ></TD>

       <TD align=center><INPUT TYPE = button VALUE=' / ' onClick=" Oper('/') "></TD>

       <TD align=center><INPUT TYPE = button VALUE='sqr' onClick="SQRT()"></TD>

   </TR>

   <TR>

       <TD align=center><INPUT TYPE = button VALUE='MR' onClick="Memory('Read')" ></TD>

       <TD align=center><INPUT TYPE = button VALUE=' 4 ' onClick="Digit(4)" ></TD>

       <TD align=center><INPUT TYPE = button VALUE=' 5 ' onClick="Digit(5)" ></TD>

       <TD align=center><INPUT TYPE = button VALUE=' 6 ' onClick="Digit(6)" ></TD>

       <TD align=center><INPUT TYPE = button VALUE=' * ' onClick=" Oper('*')"></TD>

       <TD align=center><INPUT TYPE = button VALUE=' % ' onClick="Percent()"></TD>

   </TR>

   <TR>

       <TD align=center><INPUT TYPE = button VALUE='MS' onClick="Memory('Set')" ></TD>

       <TD align=center><INPUT TYPE = button VALUE=' 1 ' onClick="Digit(1)" ></TD>

       <TD align=center><INPUT TYPE = button VALUE=' 2 ' onClick="Digit(2)" ></TD>

       <TD align=center><INPUT TYPE = button VALUE=' 3 ' onClick="Digit(3)" ></TD>

       <TD align=center><INPUT TYPE = button VALUE=' - ' onClick="Oper('-')" ></TD>

       <TD align=center><INPUT TYPE = button VALUE='1/x' onClick="Onediv()"></TD>

   </TR>

   <TR>

       <TD align=center><INPUT TYPE = button VALUE='M+' onClick="Memory('Add')"></TD>

       <TD align=center><INPUT TYPE = button VALUE=' 0 ' onClick="Digit(0)" ></TD>

       <TD align=center><INPUT TYPE = button VALUE='+/-' onClick="Changesign()"></TD>

       <TD align=center><INPUT TYPE = button VALUE='  . ' onClick="Dot()"></TD>

       <TD align=center><INPUT TYPE = button VALUE=' +'  onClick=" Oper('+') " ></TD>

       <TD align=center><INPUT TYPE = button VALUE=' =  ' onClick=" Oper('=')" NAME='EQ' onKeypress="Analyzethis('1')" ></TD>

   </TR>

</TABLE>

<INPUT TYPE=button NAME=addfeatures VALUE="More Options" onClick="MoreOptions()">

<TABLE border=0>

<TD>      </TD>

<TD>

<TABLE border=4>

   <TR>

       <TD><INPUT TYPE = button VALUE="x^2"  NAME=opt1 onClick="Advfunction(0)" onFocus="document.calc.EQ.focus()"></TD>

       <TD><INPUT TYPE = button VALUE="2^x"  NAME=opt2 onClick="Advfunction(1)" onFocus="document.calc.EQ.focus()"></TD>

       <TD><INPUT TYPE = button VALUE="x^y"  NAME=opt3 onClick="Advfunction(2)" onFocus="document.calc.EQ.focus()"></TD>

       <TD><INPUT TYPE = button VALUE="x^3"  NAME=opt4 onClick="Advfunction(3)" onFocus="document.calc.EQ.focus()"></TD>

   </TR>

</TABLE>

</TD>

 <TD> </TD></TR>

</TABLE>

</CENTER>

</FORM>

<p><center>

 <p></p>

 </center><p>                                                                                                         


 

 


I just try once  ;D


akulion

  • Guest
Re: A calculator on a script/html block, may be ?
« Reply #1 on: May 19, 2006, 03:58:41 AM »
I havent tested it yet...but thanks :D

Added to block code Snippet Index under "C" Calculator

Offline Crip

  • Jesus Inside.
  • Themes
  • *
  • Posts: 4168
  • Theme Support
    • Cripzone
Re: A calculator on a script/html block, may be ?
« Reply #2 on: May 19, 2006, 04:19:58 AM »
Demo? >:D
I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes


Offline IchBin

  • Friends
  • *
  • Posts: 16231
Re: A calculator on a script/html block, may be ?
« Reply #3 on: May 19, 2006, 10:25:16 AM »
I think it would be much better if we posted any "long" code snippets like this in a file attachment.

rbh

  • Guest
Re: A calculator on a script/html block, may be ?
« Reply #4 on: May 20, 2006, 12:01:11 PM »
couldnt get it to work in a side block, it was all screwed up. it was a caculator, and it worked just fine, but the way it displayed on my site in a left block was all jacked up. it was suppose to be the second block but as you can see it placed itself beside the first block. anyways, i did put it in a small pop up and just placed a link to it and that worked.


URPG

  • Guest
Re: A calculator on a script/html block, may be ?
« Reply #5 on: May 29, 2006, 05:15:15 PM »
How did you do the Popup?

theintensity

  • Guest
Re: A calculator on a script/html block, may be ?
« Reply #6 on: May 31, 2006, 05:01:23 AM »
How did you do the Popup?


Code: [Select]
<a href="#" onClick="popupWindow('/URL','ITEM','width=??,height=??')"> 
NAME OF ITEM</a>

URPG

  • Guest
Re: A calculator on a script/html block, may be ?
« Reply #7 on: May 27, 2007, 06:22:41 AM »
Can someone tell me where to put the file, so i can use the "link" function of the menu block?

And... THIS is a nifty looking calculator, could someone do a "floating" calculator like this, adapting to themes maybe? http://javascript.internet.com/math-related/floating-calculator.html

misjka

  • Guest
Re: A calculator on a script/html block, may be ?
« Reply #8 on: July 16, 2007, 02:00:04 PM »
Try this co

Ahh, worked like a charm and pretty advanced it  was too :) ! I added it in an article, since it requires some space...

Thanks!