Results 1 to 4 of 4

Thread: How to make a four function calculator in HTML

  1. #1
    Join Date
    Dec 2005
    Posts
    136

    How to make a four function calculator in HTML

    I would like to have a four-function calculator and made some code for it in HTML but the problem is that it doesent calculate precisely. I have also searched on websites for web based calculators but it is not what I require. Is there someone who can make this work correctly. Thank you
    wus up everybody?

  2. #2
    Join Date
    Dec 2007
    Posts
    1,599

    Re: How to make a four function calculator in HTML

    Have you looked at using the asciimath calculator? Demo here: http://www1.chapman.edu/~jipsen/math...alculator.html
    This can be embedded anywhere, modded to your hearts content and provides rather extensive ability to display math as well as graphs

  3. #3
    Join Date
    Dec 2007
    Posts
    1,736

    Re: How to make a four function calculator in HTML

    Hope this helps you

    Code:
    <!-- experiments with table & button-input  vegaseat  2/13/02 -->
    <!-- table, border, cellpadding, cellspacing, input, onClick -->
    <!-- uses eval() to do the final calculation -->
    <!-- note: eval() traps divide by zero error -->
    
    <html>
    <head>
    
    	<title>A Simple Four-Banger</title>
    	
    </head>
    <body>
    
    <form name="calculator">
    
    <!-- form the display to match the keypad -->
    <table border="4" cellpadding="1" bordercolor="#FFFFFF" bgcolor="#73B27B" cellspacing="2" width="222">
    <tr>
    <td>
    <input type="text" size="25" length="25" value="" name="ans" style="background:beige;color:black;">
    </td>
    </tr>
    </table>
    
    <!-- form the keypad with buttons in a table -->
    <table border="4" cellpadding="2" bordercolor="#FFFFFF" cellspacing="2" width="150" bgcolor="#73B27B">
    <tr>
    <td align="center">
    <input type="button" value="  7  " name="seven" onClick="document.calculator.ans.value+='7'">
    </td>
    <td align="center">
    <input type="button" value="  8  " name="eight" onClick="document.calculator.ans.value+='8'">
    </td>
    <td align="center">
    <input type="button" value="  9  " name="nine" onClick="document.calculator.ans.value+='9'">
    </td>
    <td align="center">
    <input type="button" value="  /  " name="divide" onClick="document.calculator.ans.value+='/'">
    </td>
    </tr>
    <tr>
    <td align="center">
    <input type="button" value="  4  " name="four" onClick="document.calculator.ans.value+='4'">
    </td>
    <td align="center">
    <input type="button" value="  5  " name="five" onClick="document.calculator.ans.value+='5'">
    </td>
    <td align="center">
    <input type="button" value="  6  " name="six" onClick="document.calculator.ans.value+='6'">
    </td>
    <td align="center">
    <input type="button" value="  *  " name="multiply" onClick="document.calculator.ans.value+='*'">
    </td>
    </tr>
    <tr>
    <td align="center">
    <input type="button" value="  1  " name="one" onClick="document.calculator.ans.value+='1'">
    </td>
    <td align="center">
    <input type="button" value="  2  " name="two" onClick="document.calculator.ans.value+='2'">
    </td>
    <td align="center">
    <input type="button" value="  3  " name="three" onClick="document.calculator.ans.value+='3'">
    </td>
    <td align="center">
    <input type="button" value="  -  " name="subtract" onClick="document.calculator.ans.value+='-'">
    </td>
    </tr>
    <tr>
    <td align="center">
    <input type="button" value="  C  " name="clear" onClick="document.calculator.ans.value=''">
    </td>
    <td align="center">
    <input type="button" value="  0  " name="zero" onClick="document.calculator.ans.value+='0'">
    </td>
    <td align="center">
    <input type="button" value="  =  " name="equal" 
      onClick="document.calculator.ans.value=eval(document.calculator.ans.value)">
    </td>
    <td align="center">
    <input type="button" value="  +  " name="add" onClick="document.calculator.ans.value+='+'">
    </td>
    </tr>
    </table>
    
    </form>
    
    </body>
    </html>
    Source: Daniweb

  4. #4
    Join Date
    Dec 2007
    Posts
    1,547

    Re: How to make a four function calculator in HTML

    You can also make Four Function Calculator using Java and Swing

    Overview
    The calculator is window with a menu bar, single-line text display and buttons. The user can only enter data using the buttons in the display and keyboard input is disabled. The text display and buttons are laid out in a tabular format. The menu bar has File / Exit and Help / About menu items.

    Folder Structure
    To facilitate discussion, below is the folder structure of the source code:

    ./src:
    infixcalculator resources

    ./src/infixcalculator:
    AboutAction.java HelpAction.java InfixCalculatorResource.java
    ExitAction.java images Main.java
    FileAction.java InfixCalculator.java Model.java

    ./src/infixcalculator/images:
    InfixCalculator_32x32.gif InfixCalculator_32x32.xcf

    ./src/resources:
    InfixCalculator.properties


    For more info go to this link.

Similar Threads

  1. How to Make Text Invisible in HTML Code?
    By MarceloQuad in forum Software Development
    Replies: 4
    Last Post: 04-02-2010, 06:34 AM
  2. How to make scrolling text stable in HTML
    By Caelaan in forum Software Development
    Replies: 5
    Last Post: 22-01-2010, 09:58 PM
  3. Replace calculator with Command Line Calculator
    By Eric B in forum Windows Software
    Replies: 3
    Last Post: 07-05-2009, 04:32 PM
  4. make a space in html document
    By SSupDawg in forum Software Development
    Replies: 2
    Last Post: 26-01-2009, 03:32 PM
  5. Make a form in HTML, CSS, PHP
    By Gyan Guru in forum Guides & Tutorials
    Replies: 1
    Last Post: 11-11-2008, 06:26 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,197,781.75947 seconds with 17 queries