473,597 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculate Form


All I need is a simle calculate form script which contains this:

A script that can handle text input, radio buttons, checkboxes, and
dropdowns. Each one of these variables will contain a number. That number
will appear in a seperate box at the bottom. So basically whatever you choose
has a corresponding number associated with it (except for the text input,
which you enter whatever number) and those numbers are added and produced in
a separate box at the bottom (i.e. Total Cost).

I have looked all over the Internet and cannot find a script that will insert
the total for all the various field types. Seems Im only find calculators
that produce a total number from input text fields only.

Can anyone help me? Please?

Jul 20 '05 #1
1 9978
Building Blocks <le******@myway .com> wrote in message news:<00******* *************** *******@news.ea st.cox.net>...
A script that can handle text input, radio buttons, checkboxes, and
dropdowns. Each one of these variables will contain a number. That number
will appear in a seperate box at the bottom. So basically whatever you choose
has a corresponding number associated with it (except for the text input,
which you enter whatever number) and those numbers are added and produced in
a separate box at the bottom (i.e. Total Cost).
This looks like a school assignment :-)
I have looked all over the Internet and cannot find a script that will insert
the total for all the various field types.

You should have split your search on how to grab values from different
form controls, and then how to add them (string to number conversion).
Anyway, below's a short example, which should give you enough
information to get the different points. I've gone for a regular
quantity/price calculation problem, which is where you seem to be

Note that I use a unary "+" to convert from a string to a number,
which has the advantage of being short, fast, and automatically
dealing with octal numbers. I've also used an OO conception, which
should offer a neater approach to the problem and provide you with a
much more interesting experience ;-)

<title>Calculat or Exemple</title>
<style type="text/css">
fieldset{border :2px #000 solid;padding:1 em;}
td{padding:0.4e m;vertical-align:top;font-size:0.9em}
#result{border: thin #fff solid;color:gre en;font-weight:700;}
<script type="text/javascript">
function Calculator(){ this.articles={ }; }
Calculator.prot otype.addArticl e = function (art){
Calculator.prot otype.getTotal = function(){
var total = 0;
for(var ii in this.articles)
total += this.articles[ii].getValue();
return total;
Calculator.prot otype.getArticl e = function(s){
return this.articles[s] || null;
function Article(name, price, quantity){
this.name = name;
this.price = price || 0;
this.quantity = quantity || 0;
Article.prototy pe.getValue = function(){
return this.price * this.quantity;
Article.prototy pe.setQuantity = function(q){ this.quantity = q; }
var myCalculator = new Calculator();
myCalculator.ad dArticle(new Article("Arrows ", 10, 0));
myCalculator.ad dArticle(new Article("Deku Seeds", 5, 0));
myCalculator.ad dArticle(new Article("Biggor on Sword", 200, 0));
myCalculator.ad dArticle(new Article("Din's Fire", 70, 0));
myCalculator.ad dArticle(new Article("Farore 's Wind", 50, 0));
function calculate(butto n){
frm=button.form ,
qArrows=frm.ele ments["artArrows"].value,
+ frm.elements["artDekuSee ds"].options[
frm.elements["artDekuSee ds"].selectedIndex].value,
qBiggoronSword= frm.elements["artBiggoronSwo rd"].checked ? 1 : 0,
qDinsFire=frm.e lements["artMagics"][0].checked ? 1 : 0,
qFaroresWind=fr m.elements["artMagics"][1].checked ? 1 : 0;

qArrows = /^\d+$/.test(qArrows) ? + qArrows : 0

myCalculator.ge tArticle("Arrow s").setQuantity (qArrows);
myCalculator.ge tArticle("Deku Seeds").setQuan tity(qDekuSeeds );
myCalculator.ge tArticle("Biggo ron Sword").
setQuantity(qBi ggoronSword);
myCalculator.ge tArticle("Din's Fire").setQuant ity(qDinsFire);
myCalculator.ge tArticle("Faror e's Wind").
setQuantity(qFa roresWind);

frm.elements["result"].value = myCalculator.ge tTotal() + "r";
<form action="whateve r.foo" onsubmit="retur n false">
<legend>Article s</legend>
<p>Please select your articles and quantities below.</p>
<table cellspacing="0" >
<td><label for="artArrows" >Arrows (10r)</label></td>
<input type="text" id="artArrows" name="artArrows "
value="10" onblur="calcula te(this)">
<td><label for="artDekuSee ds">Deku Seeds (5r)</label></td>
<select name="artDekuSe eds" id="artDekuSeed s"
onchange="calcu late(this)">
<option value="0">0</option>
<option value="10">10</option>
<option value="20">20</option>
<label for="artBiggoro nSword">
Do you want the Biggoron Sword (200r)?
<input name="artBiggor onSword" id="artBiggoron Sword"
type="checkbox" checked="checke d"
onclick="calcul ate(this)">
<td rowspan="2">Mag ics</td>
<input type="radio" name="artMagics " id="artDinsFire "
value="artDinsF ire_1" checked="checke d"
onclick="calcul ate(this)">
<label for="artDinsFir e">Din's Fire (70r)</label>
<input type="radio" name="artMagics " id="artFaroresW ind"
value="artFaror esWind_1" onclick="calcul ate(this)">
<label for="artFarores Wind">Farore's Wind (50r)</label>
<input type="button" value="Calculat e!"
onclick="calcul ate(this)">
<input type="text" name="result"
id="result" readonly="reado nly">
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is difficult to know what is going on. One of these Order Forms you can see here... http://www.cardman.co.uk/orderform.php3
by: jochen scheire | last post by:
Is there a way I can calculate a field in a form based on another field in the same form. When clicking submit, both values should be posted to the next page. I want to be able to type in a value in one field, and automatically in a second field the value*1,36 should appear.
by: Jan Szymczuk | last post by:
I'm creating an MS Access 2000 database where I have a number of people entered using simple basic fields, Surname: SMITH Forenames: John DoB: 09/09/1958 Age: (this needs to be automated to show years e.g. 46) I am trying to get the age to be automatically shown after a persons DoB (date of birth) is entered into the DoB field. I have tried using this formula in the Control Source of the Age field...
by: Drew Leon | last post by:
I have a Tab Control on a form. Each one of the tabs have two populated List Boxes on them. I have a Button on the form which I would like to use to calculate the various math problems in the Tabs. I would rather not have to a button on each tab to calculate the math problems. Any assistance would be greatly appreciated. Thank you, Drew Leon -- Have a great day! Drew Leon
by: Rich_C | last post by:
I'm sure this is very simple, but I have very little experience with javascript -- and what I do know isn't helping me here. I have a simple form where users can enter a quantity (qty) and cost (cost). Users can dynamically add rows to the table so I don't know how many rows might need to be calculated. I need to calculate the total (qty * cost) and put that number in a table cell (or read only input box). I also need to sum the...
by: luanhoxung | last post by:
dear all!! i met the headache problem in setting value for some controls in my form. i have 2 combo box in form F1. i want to set value for some textbox in F1 when i choose value from 2 combo box. the value calculated of these textbox base on some fields of table T1 in condition: the same value between 2 combox-F1 and 2 fields-T1. hereunder is my code: Private Sub PACKAGE_AfterUpdate() Dim MyDB As Database
by: reidarT | last post by:
I have 3 fields in an aspx page. The 3. field should be the sum of field A and field B I use OnTextChanged to calculate the sum in field3. At the same time I want to insert the content of theese 3 fields into a row in a table. The problem is that I need 'postback is true' on the textfields to get an immediate calculation and then the insert action is triggered. reidarT
by: chunk1978 | last post by:
hey... can anyone show me how to calculate sums to the 2nd decimal only? like: 5.50 + 4.00 = 9.50 i seriously have zero idea and could defo use some help...thanks! <script type="text/javascript"> <!--
by: brendanmcdonagh | last post by:
Hi, I have been learning VB now for about a week and thought I was doing ok. I have already done a calculation form (not as big as this) . I have volunteered myself to help a friend input her hours per day into a form, start time, end time and lunch time. Then the form will calculate the amount of hours she has done for her. Sending results to access is not an issue yet! When I have entered the below code and tested it, it let's me input...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.