Hi guys,
I have run into a problem and I can't figure out what's happening or why this script won't work. I am a self-taught scripter and only know what I use really. Any help would be appreciated. OK, here's the problem:
I have a total of 5 dollar fields that will be calculated into a 6th dollar field. An example of what I need is like -------- field1 + field2 + field3 + field4 * field5. The answer to all of that gets put into the 6th field, which will also need to be rounded to the nearest whole $. The only thing I want rounded is the answer, not the individual fields themselves. Also, one thing that I know for sure is wrong (and something I don't know how to do) is the fact that all the fields are optional. Meaning, maybe there will be input in them, and maybe there won't. I just have no idea how to script that. Here's what I've got that isn't working-------------- -
var a = this.getField("LO");
-
var b = this.getField("PP");
-
var c = this.getField("AEC");
-
var d = this.getField("UM");
-
var e = this.getField("TOT");
-
event.value = Math.round(a.value+b.value+c.value+d.value*e.value);
-
I have tried putting the individual values into ( ) by themselves, which doesn't make a difference. ---------- One thing that I noticed that was happening is that when you only enter a value in the first 2 fields, it would get multiplied by 10 for some reason. Then the 3rd field would bring it back to the correct answer, and then the 4th wouldn't have any effect. (Using the value of 1 in all fields.) So 1+1 would show, a total of 20. 1+1+1 would be 3. 1+1+1+1 would be 3. ---------- Any help would be appreciated guys. Thank you!!!
3 1265 iam_clint 1,208
Recognized Expert Top Contributor
I would do something like this. -
var a = this.getField("LO");
-
var b = this.getField("PP");
-
var c = this.getField("AEC");
-
var d = this.getField("UM");
-
var e = this.getField("TOT");
-
if (a=="") { a = 0; }
-
if (b=="") { b = 0; }
-
if (c=="") { c = 0; }
-
if (d=="") { d = 0; }
-
if (e=="") { e = 0; }
-
var answer = Math.floor(a.value+b.value+c.value+d.value*e.value);
-
//var answer = Math.floor(a.value+b.value+c.value+d.value)*e.value; //depends on how you want it calculated a.value+b.value+c.value+d.value = blah * e.value is how this is your other one could be interpreted d.value*e.value+c.value+b.value+a.value
-
event.value = Math.round(answer);
-
Thanks iam_clint. That pushed me in the right direction. Response very much appreciated!!! Looks like I'll meet my deadline! : )
So to use the if statement to make a field equal 0.00 if there is no input, would I have to name the variable the field I am working with and then use the if statement you gave me? Example: -
-
var a = this.getField("LO");
-
if (a=="") { a = 0.00; }
-
-
Do I understand you correctly?
iam_clint 1,208
Recognized Expert Top Contributor
yes, also 0.00 is the same as just 0.
And you are putting a space [ /CODE] like this you need to take that space out for posting here.
Sign in to post your reply or Sign up for a free account.
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: Sean McCourt |
last post by:
Hi I am doing a JavaScript course and learning from the recommed book
(JavaScript 3rd Edition by Don Gosslin)
Below is one of the exercises from the book. I get this error message
when I try to use the calculator.
"document.Calculate.Input is null or not an object"
Can someone please tell me why this is?
|
by: anaxamandr |
last post by:
Hi.
I have a long loop in ASP that performs a rather lengthy calculation. I would love for my users to be able to stop that calculation, if they so choose, mid way through the process.
I attempted to use a parent window that allows the user to launch the calculation in a seperate window, so that they could still click "stop" to write a value to a database or set a session level variable that the calculation would check to see if it should...
|
by: Matt Kruse |
last post by:
http://www.JavascriptToolbox.com/bestpractices/
I started writing this up as a guide for some people who were looking for
general tips on how to do things the 'right way' with Javascript. Their code
was littered with document.all and eval, for example, and I wanted to create
a practical list of best practices that they could easily put to use.
The above URL is version 1.0 (draft) that resulted. IMO, it is not a
replacement for the FAQ,...
|
by: Del |
last post by:
Thanks in advance for any help.
I have a database that was created in Access 2000. Several users have
been upgraded to Access 2003. Since upgrading to 2003 we have noticed
that some of the calculated fields are not being populated. The
database is a samll invoicing database on the form and report we have
columns call Unit Cost. This is the actual cost of the part and is
pulled from our parts master table and is displayed in a sub form...
| |
by: Michiel Alsters |
last post by:
Hello everybody,
I hope anybody can help me. I'll try to give a brief overview of my
problem. I have running a program that performs a heavy calculation.
To give the user feedback what the program is doing I show a window
which contains a progress bar and a label. At some point during the
execution the state of the calculation is changed, so I want to let
the user know this.
I have placed the creation of the form in a seperate thread...
|
by: google |
last post by:
I would like to execute a single JavaScript command from within a web
service. The command is a mathmatical statement.
I have a web page with some client side logic that does this and I'm
now moving that functionality into a web service.
To clarify - on the UI the user is collecting and entering data and
then it gets stored into the database. Most fields are input but
there are some that are calculated and stored. The calculated...
|
by: theflyingminstrel |
last post by:
Hi, I’m having some trouble with a Javascript code, and I was wondering if anyone can help:
I am trying to build a price estimator that has multiple fields. I would like the first two fields to have a price value based on a quantity price, so for example 1-10 qantity equals $30, 20-30 quantity equals $40 in the “Total” field). The rest of the fields in the following code work as intended whereas they just add based on the price to the right....
|
by: =?Utf-8?B?R1ROMTcwNzc3?= |
last post by:
Hi Guys, thanks for your help yesterday, I've got one more question, then I
think I'm done for now,...
Is it possible to insert recordset data in a javascript, for instance I have
a javascript code that calculates the total price, depending on number of
units, currently what the code does is set the price like so -
if qty 1 then £99+VAT
if qty equall to or greater than 2 and equall to or less than 9 then price =
|
by: Jon Harrop |
last post by:
What is the shortest and simplest Javascript implementation and where can I
find a BNF for this language?
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?u
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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: 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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |