If you have a Web site where your visitor would find an online calculator very handy, with a little Java Script code you can easily provide a custom calculator right on your Web page.
Welcome to Bucaro TecHelp!

Welcome to Bucaro TecHelp!
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

[About BTH]  [User Agreement]  [Privacy Policy]  [Site Map]  [Contact Form]  [Advertise on BTH]  [News Feed]

Google
Web
This Site

Get The Hottest Natural Health Newsletters Free!

Natural Health Newsletters Free!

[ ] Alternative Medicine
[ ] Anti-Aging
[ ] Aromatherapy
[ ] Back pain Relief
[ ] Herbal Remedies
[ ] Magnetic Therapy
[ ] Natural Nutrition
[ ] Vitamin Research
[ ] Weight Loss

Click here to see all of our newsletters, and sign up for the ones you want!

Join American Consumer Opinion™ and Get Paid Cash!
Get paid $4 to $25 for each survey
Typically $4 to $25 for each survey.
Click Here to join (Available worldwide)

Calculators For Your Web Site

Maybe you have a Web site where your visitor would find an online calculator very handy. Maybe you have a crafting instruction site where the visitor needs to calculate some dimensions. Or maybe you have an investment site where the visitor needs to calculate some money numbers. With a little Java Script code you can easily provide a custom calculator right on your Web page.

What makes this possible is Java Script's powerful built-in eval() function. All you have to do is provide the eval function with a mathematical expression in a string (computerese for a sentence inside quotes) and the eval() function will convert the string to the proper numbers and operators and return the result of the expression. For example, the statement below returns the number 12.

eval("2 * 6");

And if the eval() function isn't powerful enough for you, Java Script also has a built-in Math object that you can use to perform square roots, logarithms, trigonometric functions, and much more. You could build a full-featured scientific calculator for your Web page.

Below is a quick little basic calculator. Nothing fancy here. I'm sure you could easily make one with more powerful features that looks much better.

   

The process of building a calculator requires three main steps: 1. Build an html form; 2. Write Java Script functions to process the data from the form - basically using the eval() function; 3. Display the results of the calculation.

The calculator above uses only two small functions, enterNumber(digit) and calculate(operation). Two other tiny functions, clearEntry(form) and clearAll(form) are used to clear the calculator. When you click on one of the digit buttons, the buttons onClick event calls the enterNumber(digit) function as shown below.

<input type="button" name="7" value="7" onClick="enterNumber(this);">

function enterNumber(digit)
{
   if(newNumber)
   {
      clearEntry(digit.form);
      newNumber = false;
   }

   if(digit.value == "." && !decimalSet)
   {
      digit.form.display.value = 
         digit.form.display.value + digit.value;
       decimalSet = true;
   }
   else
   {
      digit.form.display.value = 
         digit.form.display.value + digit.value;
   }
}

Note the "this" keyword passed to the enterNumber(this) function. This passes the button object to the function. Apparently each element of a form contains a property that is a pointer to the parent form object because you can use the button.form operator to access other elements in the form. If you didn't understand that last sentence, don't worry - neither did I!

Web Design Sections

RSS Feed RSS Feed

Easy Java Script Code
Easy Java Script Windows
Easy Rollovers
Easy Picture Transition Effects
Easy Moving Popup Code
Easy Slide Show Code
Easy Slide Show Code With Linked Slides
Slide Show with Different Size Images
Easy Picture Zoom Code
Easy Picture Panning Code
Easy Java Script Animation
Easy JavaScript Picture Selector Code
Easy Animated Banners with Java Script
Easy Java Script Form Validation
Easy Drag n Drop Code
Easy Graph Generating Code
Easy Code to Sort a Table by Column
Easy Fading Text Banner Code
Easy Expanding Banner Code
Calendars for Your Website
Date Picker For Your Web Site
Calculators For Your Web Site
Loan Payment Calculator
Length Units Converter
Body Mass Index
Fahrenheit to Celsius Converter
Decimal to Hexidecimal Converter
Easy Code for Screen Tape Adding Machine
Code for Java Script Circle⁄Sphere Calculator
Round a Float to 4 Digits to the Right of the Decimal Point
Make Your Own Graphical Digital Clock
Let Your Web site Visitors Set Font Size
How to Disable the Browser Back Button
Add More Bang to Your Content With Keyword Popup Menus
Put a Music Off Switch on Your Webpage
Java Script Random Password Generator
Password Protection Using Java Script
Replace Drop-down with Drag-and-drop
Submit Forms Without CGI
Code for a Less annoying Popup Window
Using the Java Script Array Object
Using the Java Script Date Object
Java Script Message Boxes
How to Shuffle the Deck With Java Script
Web Site Menus : Which Section Am I In?
How Far Did the User Scroll?
Where Did the User Click?
Four Ways to Use Java Script Event Handlers
Create Your Own Database Using Only Notepad : CDV

[Site User Agreement]  [Advertise on This site]  [Search This Site]  [Contact Form]
Copyright©2001-2007 Bucaro TecHelp P.O.Box 18952 Fountain Hills, AZ 85269