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 Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact Advertise on Bucaro TecHelp Advertise Here RSS News Feeds News Feeds

HTML5 Solutions: Essential Techniques for HTML5 Developers

Essential Techniques for HTML5 Developers

HTML5 brings the biggest changes to HTML in years. Web designers now have new techniques, from displaying video and audio natively in HTML, to creating realtime graphics on a web page without a plugin.

This book provides a collection of solutions to all of the most common HTML5 problems. Every solution contains sample code that is production-ready and can be applied to any project.

Click Here

Coding Java Script 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!

RSS Feed RSS Feed



Web Design Sections

Eloquent JavaScript: A Modern Introduction to Programming

Eloquent JavaScript

Eloquent JavaScript Eloquent JavaScript goes beyond the cut-and-paste scripts of the recipe books and teaches you to write code that's elegant and effective. You'll start with the basics of programming, and learn to use variables, control structures, functions, and data structures. Then you'll dive into the real JavaScript artistry: higher-order functions, closures, and object-oriented programming.

Reader Anthony says, "This book is not your typical Javascript book. Others have a utilitarian approach. In stark contrast, Eloquent JavaScript does not merely provide you a checklist of things to learn but rather paints a panorama of the possibilities that programming provides. Javascript is merely the tool used to introduce these to the reader.

Click here for more information.


[Site User Agreement] [Advertise on This site] [Search This Site] [Contact Form]
Copyright©2001-2011 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268