Adblock breaks this site

Need Basic Javascript Help

Discussion in 'Web Programming' started by timithyy, Sep 10, 2015.

  1. timithyy

    timithyy Apprentice
    $25 USD Donor New

    Joined:
    Jun 10, 2011
    Posts:
    680
    Referrals:
    0
    Sythe Gold:
    0
    Christmas 2015 SytheSteamer
    Need Basic Javascript Help

    Hi guys I'm just a beginner at javascript/html. I'm trying to finish off this calculator and am having troubles adding the division and multiply signs in (and making them functional), if someone could show me how to do that it would be much appreciated :)

    Code:
    <!DOCTYPE html>
    <CENTER>
     <FORM name="Keypad" action="">
      <TABLE>
      <B>
      <TABLE border=2 width=50 height=60 cellpadding=1 cellspacing=5>
       <TR>
          <TD colspan=3 align=middle>
             <input name="ReadOut" type="Text" size=24 value="0" width=100%>
          <TD
          </TD>
          <TD>
             <input name="btnClear" type="Button" value="  C  " onclick="Clear()">
          </TD>
          
    	  <TD><input name="btnClearEntry" type="Button" value="  CE " onclick="ClearEntry()">
          </TD>
       </TR>
       
       <TR>
          <TD>
             <input name="btnSeven" type="Button" value="  7  " onclick="NumPressed(7)">
          </TD>
          <TD>
             <input name="btnEight" type="Button" value="  8  " onclick="NumPressed(8)">
          </TD>
    	  <TD>
             <input name="btnNine" type="Button" value="  9  " onclick="NumPressed(9)">
          </TD>
    	  <TD>
          </TD>
    	  <TD>
             <input name="btnNeg" type="Button" value=" +/- " onclick="Neg()">
          </TD>
    	  <TD>
             <input name="btnPercent" type="Button" value="  % " onclick="Percent()">
          </TD>
       </TR>
    
       <TR>
          <TD>
             <input name="btnFour" type="Button" value="  4  " onclick="NumPressed(4)">
          </TD>
          <TD>
             <input name="btnFive" type="Button" value="  5  " onclick="NumPressed(5)">
          </TD>
          <TD>
             <input name="btnSix" type="Button" value="  6  " onclick="NumPressed(6)">
          </TD>
          <TD>
          </TD>
          <TD align=middle><input name="btnPlus" type="Button" value="  +  " onclick="Operation('+')">
          </TD>
          <TD align=middle><input name="btnMinus" type="Button" value="   -   " onclick="Operation('-')">
          </TD>
       </TR>
    
       <TR>
         <TD>
            <input name="btnOne" type="Button" value="  1  " onclick="NumPressed(1)">
         </TD>
         <TD>
            <input name="btnTwo" type="Button" value="  2  " onclick="NumPressed(2)">
         </TD>
         <TD>
            <input name="btnThree" type="Button" value="  3  " onclick="NumPressed(3)">
         </TD>
         <TD>
         </TD>
         <TD align=middle><input name="btnMultiply" type="Button" value="     " onclick="">
         </TD>
         <TD align=middle><input name="btnDivide" type="Button" value="       " onclick="">
         </TD>
      </TR>
    
      <TR>
         <TD>
            <input name="btnZero" type="Button" value="  0  " onclick="NumPressed(0)">
         </TD>
         <TD>
            <input name="btnDecimal" type="Button" value="   .  " onclick="Decimal()">
         </TD>
         <TD colspan=3>
         </TD>
         <TD>
            <input name="btnEquals" type="Button" value="  =  " onclick="Operation('=')">
         </TD>
      </TR>
    
       </TABLE>
      </TABLE>
      </B>
      </FORM>
    </CENTER>
    <font face="Verdana, Arial, Helvetica" size=2>
    
    <SCRIPT LANGUAGE="JavaScript">
       <!-- Begin
          var FKeyPad = document.Keypad;
          var Accumulate = 0;
          var FlagNewNum = false;
          var PendingOp = "";
    
    	  function NumPressed (Num) {
                   if (FlagNewNum) {
                      FKeyPad.ReadOut.value  = Num;
                      FlagNewNum = false;
                   }
                   else {
                        if (FKeyPad.ReadOut.value == "0")
                           FKeyPad.ReadOut.value = Num;
                        else
                           FKeyPad.ReadOut.value += Num;
                   }
          }
    
    	  
    	  function Operation (Op) {
                   var Readout = FKeyPad.ReadOut.value;
    
    			   if (FlagNewNum && PendingOp != "=");
                   else
                   {
                    FlagNewNum = true;
                    if ( '+' == PendingOp )
                       Accumulate += parseFloat(Readout);
                    else if ( '-' == PendingOp )
                            Accumulate -= parseFloat(Readout);
                    else
                        Accumulate = parseFloat(Readout);
                     FKeyPad.ReadOut.value = Accumulate;
                     PendingOp = Op;
                   }
          }
    
    	  
    	  function Decimal () {
                  var curReadOut = FKeyPad.ReadOut.value;
    
    			  if (FlagNewNum) {
                      curReadOut = "0.";
                      FlagNewNum = false;
                  }
                  else
                     {
                      if (curReadOut.indexOf(".") == -1)
                         curReadOut += ".";
                     }
    
    		      FKeyPad.ReadOut.value = curReadOut;
          }
    	  
    	  
          function ClearEntry () {
                FKeyPad.ReadOut.value = "0";
                FlagNewNum = true;
          }
    	  
    	  
          function Clear () {
                Accumulate = 0;
                PendingOp = "";
                ClearEntry();
          }
    
    	  
    	  function Neg () {
                FKeyPad.ReadOut.value = "###";
          }
    
    	  
    	  function Percent () {
               FKeyPad.ReadOut.value = (parseFloat(FKeyPad.ReadOut.value) / 100) * parseFloat(Accumulate);
    }
    // End -->
    </SCRIPT>
     
  2. SuF

    SuF Legend
    Pirate Retired Global Moderator

    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary
    Need Basic Javascript Help

    What issues are you having specifically?
     
  3. timithyy

    timithyy Apprentice
    $25 USD Donor New

    Joined:
    Jun 10, 2011
    Posts:
    680
    Referrals:
    0
    Sythe Gold:
    0
    Christmas 2015 SytheSteamer
    Need Basic Javascript Help

    Making the multiply and division buttons work. Getting the symbols * and / on the calculator itself I can do, I just need them to work.
     
  4. timithyy

    timithyy Apprentice
    $25 USD Donor New

    Joined:
    Jun 10, 2011
    Posts:
    680
    Referrals:
    0
    Sythe Gold:
    0
    Christmas 2015 SytheSteamer
    Need Basic Javascript Help

    bump.. anyone?
     
  5. Blupig

    Blupig BEEF TOILET
    $5 USD Donor

    Joined:
    Nov 23, 2006
    Posts:
    7,145
    Referrals:
    16
    Sythe Gold:
    1,609
    Discord Unique ID:
    178533992981594112
    Valentine's Singing Competition Winner Member of the Month Winner MushyMuncher Gohan has AIDS Extreme Homosex World War 3 I'm LAAAAAAAME
    Off Topic Participant
    Need Basic Javascript Help

    *= and /* are both valid operators (similar to += and -=). You just add the operations as you've already done for + and -.
     
< Anyone know a decent free/cheap VPN [Prefer free] | >


 
 
Adblock breaks this site