Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    use php instead of javascript

    hi frends dis is my code for caluculator..i use java script in dis..instead of using javascript can use php..

    Code:
    <html>
    <form action=" " method="post" name="Keypad">
        
     <table width='200' cellpadding='2' cellspacing='5' border='1'>
    <tr>
    <td colspan=3 align=middle>
    <input name="ReadOut" type="Text" size=15 value="0" width=100%>
    </td> </tr>
        <tr><td align="center">
        <input type="button" value=" 7 " name="seven" onclick="NumPressed(7)">
        </td>
        <td>
        <input type="button" value=" 8 " name="eight" onclick="NumPressed(8)">
        </td>
         <td>
        <input type="button" value=" 9 " name="nine" onclick="NumPressed(9)">
        </td>
         <td>
        <input type="button" value=" / " name="divide" onclick="Operation('/')">
        </td>
                  </tr> 
          <tr><td align="center">
        <input type="button" value=" 4 " name="four" onclick="NumPressed(4)">
        </td>
        <td>
        <input type="button" value=" 5 " name="five" onclick="NumPressed(5)">
        </td>
         <td>
        <input type="button" value=" 6 " name="six" onclick="NumPressed(6)">
        </td>
         <td>
        <input type="button" value=" * " name="multiply"  onclick="Operation('*')">
        </td>
                 </tr>
    
         <tr><td align="center">
        <input type="button" value=" 1 " name="one" onclick="NumPressed(1)">
        </td>
        <td>
        <input type="button" value=" 2 " name="two" onclick="NumPressed(2)">
        </td>
         <td>
        <input type="button" value=" 3 " name="three" onclick="NumPressed(3)">
        </td>
         <td>
        <input type="button" value=" - " name="Substraction" onclick="Operation('-')">
        </td>
                  </tr> 
    
    
    
       <tr><td align="center">
        <input name="btnClearEntry"  type="Button" value=" C " onclick="ClearEntry()">
        </td>
    
        <td>
        <input name="btnZero" type="Button" value="  0  " onclick="NumPressed(0)">
        </td>
         <td>
        <input type="button" value=" = " name="equal" onclick="Operation('=')">
        </td>
         <td>
        <input type="button" value=" + " name="add" onclick="Operation('+')">
        </td>
                  </tr> 
    </table>
    </form>
    <?php
    
    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 if ( '/' == PendingOp )
    Accumulate /= parseFloat(Readout);
    else if ( '*' == PendingOp )
    Accumulate *= parseFloat(Readout);
    else
    Accumulate = parseFloat(Readout);
    FKeyPad.ReadOut.value = Accumulate;
    PendingOp = Op;
      }
    }
    function ClearEntry () {
    FKeyPad.ReadOut.value = "0";
    FlagNewNum = true;
    }
    
    
    </script>
    </html>

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Yes you can use PHP?

    Have you tried doing it yourself at all?

  • #3
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ya boss i'm trying but i'm nt getting it..bcoz i'm new 4r php can u help me plz..i wnt it in pure php

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,480
    Thanks
    0
    Thanked 635 Times in 625 Posts
    So each time a key is pressed you need to submit the form and reload the page so that the PHP can read which button was pressed and perform the appropriate action.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    Regular Coder jdswebservice's Avatar
    Join Date
    Aug 2010
    Location
    Moon Township, PA
    Posts
    107
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Ok, enough with the l33t speak broski. :/ seriously, this is a coding forum. If you want to be taken at least SOMEWHAT seriously, at least use correct english.

    Now, as i seemed to have posted in another topic, this board isn't for someone just to write code for you. At least ATTEMPT writing the code yourself. If you have any errors come back and we'll be more then happy to help you.

    If you want the code to be written for you then look in the projects board/category.

    Thanks
    Jonathan R.
    Email: jonathan@logicaldevelopment.net
    Skype, Aim, & Jabber: logicaldevelopment
    Website: http://logicaldevelopment.net/

    NOTE: When contacting me please have the following things ready:

    Thread ID (This can be found in the URL of your thread)
    Budget of Project
    Methods of contacting you/your organization
    Preferred method if many methods are provided

    Any website information that you PM, Email, IM, or otherwise is strictly confidential and will not be disseminated, distributed, or copied in any way, shape or form.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •