473,378 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

calculating amounts very strange thing

http://www.ncsa.uiuc.edu/Divisions/Admin/reimb.asp

There is just too much code to place here.
onChange you trigger a function to add the numbers in the the column you
entered an amount in (scripts have been made for only the first 2 columns).
The information is passed to a second function that adds all the numbers in
the row you are in and puts a total at the end.

This part works great unless you place an "8", "88", "888", etc. in the first
row that's different than the rest (it calculates milage). If you use one of
the numbers the sum at the end does not refelct the milage.
Another issue...there is a third function called subtotal that adds all the
line totals. subtotal does not work at all.

Please give this a looksee. Thanks guys.
Jul 23 '05 #1
9 1473
Abby Lee wrote:
http://www.ncsa.uiuc.edu/Divisions/Admin/reimb.asp

This part works great unless you place an "8", "88", "888", etc. in the first row that's different than the rest (it calculates milage). If you use one of
the numbers the sum at the end does not refelct the milage.
1 entered 1 under Miles, and then 8, 88, 888, 8888, 88888, 888888 in the
columns to the right, the total=987648.38 which looks correct to me.

Another issue...there is a third function called subtotal that adds all the
line totals. subtotal does not work at all.


te['subtot'].vaue = format(ttot);
Jul 23 '05 #2
Abby Lee wrote:

[snip]
Please give this a looksee. Thanks guys.


You may also wish to add missing tags:

<!DOCTYPE ...>
<html>
<head>

It would also help greatly to add on-screen prompts for
things like time format, etc. as you've done with date.

When you validate the time, don't just clear the field
if it's wrong. Tell the user and let them either edit the
existing value or put in something completely new. Why
make them re-type the entire text (8 characters) just
because of one wrong key stroke?

Cheers, Rob.
Jul 23 '05 #3
In article <ui***************************@news.ks.uiuc.edu> ,
Abby Lee<ab*******@hotmail.com> wrote:
http://www.ncsa.uiuc.edu/Divisions/Admin/reimb.asp

There is just too much code to place here.


var eb = document.forms[0].elements;
rb = 'airRail' + itm,
t = 0;

Notice the ; after elements. I bet you wanted a comma.

Perhaps you have a global variable conflict. I don't look, you also have

var e = document.forms[0].elements;
r = 'autoReimb' + itm;
t = 0;
Something like this should align all the text in your td's.

<style type="text/css">
td {text-align: center;}
</style>

Robert
Jul 23 '05 #4
http://www.ncsa.uiuc.edu/Divisions/Admin/reimb.asp

Looks like most things was fixed with your help....however I still have the
very strangest problem.

It works great unless you put an "8", "88", etc in the miles text box.
If you use 8's the amount of reimbursement is correctly put into the "Auto
Reimburse" text box, but the "Daily Totals" for that line is "0.00" unless
you already have values in any of the other text boxes in that row...then it
adds everything except the "Auto Reimburse". Again works fine if you don't
use 8's by themselves.
Jul 23 '05 #5
Abby Lee<ab*******@hotmail.com> writes:
http://www.ncsa.uiuc.edu/Divisions/Admin/reimb.asp


8's in the milage has nothing to do with my problem excep that they figure
into even dollars....
Seems the function below does not like a value with 0 cents in it (9.00,
33.00, or 984.00). I don't seem to understand why.

function lineTotal(val, itm){
var ea = document.forms[0].elements;
var trvtps = new Array
('autoReimb','airRail','car','taxi','lodge','meals ','misc');
if(isPosInt(val.value)){
var ta = 0;
for (var i = 0; i < trvtps.length; i++){
var trvitem = trvtps[i];
if(isPosInt(ea[trvitem + itm].value)){
ta += +ea[trvitem + itm].value;
}
}
ea['total' + itm].value = format(ta);
subtotal();
}
}
Jul 23 '05 #6
Abby Lee<ab*******@hotmail.com> wrote in message news:<ui***************************@news.ks.uiuc.e du>...
http://www.ncsa.uiuc.edu/Divisions/Admin/reimb.asp This part works great unless you place an "8", "88", "888", etc. in the first
row that's different than the rest (it calculates milage). If you use one of
the numbers the sum at the end does not refelct the milage.


A mileage value of 8 leads to a cost of $3.00. A cost of 7 leads to a
cost of 2.63. The function isPosInt returns false for 3.00, but
returns true for 2.62.
Here is a postive real functions:

function isPosReal(v) {
var result2 = /^(0|[1-9])\d*\.\d+$/.test(v);
return result2;
}

I am a total novice at regular expressions. I got regular expression
via a post from M. Winter.

In lineTotal function I modified a line to read:

if(isPosReal(ea[trvitem + itm].value)){
ta += +ea[trvitem + itm].value;
}

Line total now works. Column total doesn't.

I think they say qed. Which I recall means something like solution
left to reader.

Robert
Jul 23 '05 #7
Abby Lee<ab*******@hotmail.com> wrote in message news:<ui***************************@news.ks.uiuc.e du>...

Another issue...there is a third function called subtotal that adds all the
line totals. subtotal does not work at all.


Ok, I have developed a debug function that puts up a popup window
which I can write debug information to.

Here, I am enclosing a copy of the html file with some examples and
the debug code. Just copy all the code between the script tags and
insert
<script>
// Open the debug window and display debug information
// passing false suppresses all debug information and
// the debug window.
debug(true);
</script>
after the <body> statment.

I used this code to find out that when you looked at 3.00 to determine
if it was an integer, the code was returning false.

Robert


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>javascript debug routines and tester</title>

<script type="text/javascript">

// Popup the debug window.
// You need to have enabled popup windows

// --------------------

function debug(myDebugMode) {

var theMode = myDebugMode;
var popupOk = true;

if (theMode == true)
{
var myWindowName =
document.URL.substr(document.URL.lastIndexOf("/")+1);
var thePosition = myWindowName.indexOf(".");
if (thePosition > 0)
{ myWindowName = myWindowName.substr(0,thePosition); }
myWindowName = myWindowName.replace(/%20/g,"")
// Get rid of special characters because IE won't accept them
myWindowName =
myWindowName.match(/[a-zA-Z0-9]/g).join("");

var documentContent = "javascript:" +
"if (!document.getElementById('present') )" +
"{" +
"document.open();" +
"document.writeln(" +
'\"<!DOCTYPE HTML PUBLIC \'-//W3C//DTD HTML ' +
'4.01 Transitional//EN\'>' +
"<html>" +
"<head>" +
"<title>Window " + myWindowName + "<\/title>" +
"<style type='text/css'>" +
"div p {margin: 0px;}" +
"<\/style>" +
"<\/head>" +
"<body id='present'>" +
"<div id='debugdiv'>" +
"The debug information that follows was generated on " +
Date() + "<br>&nbsp;<\/p>" +
"<\/div>" +
"<\/body>" +
"<\/html>" + "\");" +
"document.close();" +
"} " +
"else" +
"{" +
"addOn('\\xA0');" +
"var myData = 'The debug information " +
"that follows was generated on ' +" +
"Date();" +
"addOn(myData);" +
"addOn('\\xA0');" +
"}" +
"function addOn (myData) " +
"{ " +
"var node = document.getElementById('debugdiv');" +
"var myPara = document.createElement('P');" +
"node.appendChild(myPara);" +
"myPara.appendChild(document.createTextNode( myData));" +
"}";

try
{
debug.newWindow = window.open(
documentContent,
myWindowName,
"scrollbars,resizable,location,width=700,height=50 0");
}
catch(e)
{
myWindowName = "debug";
debug.newWindow = window.open(
documentContent,myWindowName);
}

}

// Example invocation & print:
// debug.dump(document,'document');

// --------------------

function dump(obj, obj_name)
{

if (theMode == true )
{
debug.out('In DumpProperties. obj=' + obj_name);
for (var i in obj)
{
try
{ debug.out(obj_name + "." + i + " = " + obj[i]); }
catch(e)
{ debug.out("Error writing out structure. Was " +
e + " for " + i); }
}
}
}

debug.dump = dump;

// --------------------

function dumpSorted(obj, obj_name)
{
var i;
var sorted = [ ];
var objCount = 0;

if (theMode == true )
{
debug.out('In DumpProperties. obj=' + obj_name);

for (i in obj)
{
sorted[objCount++] = i;
}

sorted.sort();

for ( i=0; i <sorted.length; i++)
{
try
{ debug.out(obj_name + "." + sorted[i] + " = " +
obj[sorted[i]]); }
catch(e)
{ debug.out("Error writing out structure. Was " +
i + " for " + sorted[i]); }
}

} // if we are debugging.
} // of dumpSorted

debug.dumpSorted = dumpSorted;

// --------------------

function out(obj)
{

var theString = "" + obj;

if (theMode == true )
{
theString = theString.replace(/ /g, "\xA0");
add(debug.newWindow,theString);
}

} // of out

debug.out = out;

// --------------------

function add(win,obj)
{
var node;
if (popupOk == true)
{
try
{ node = win.document.getElementById("debugdiv"); }
catch(e)
{
alert("Please wait a moment then press enter." +
"We are waiting for the popup window to " +
"complete processing.");
try
{ node = win.document.getElementById("debugdiv"); }
catch(e)
{
popupOk = false;
alert("Debugging is disabled." +
"Please ensure that popup windows" +
" are enabled the reload this page.");
return;
}
}
var myPara = win.document.createElement("P");
node.appendChild(myPara);
myPara.appendChild(win.document.createTextNode("" + obj));
}
} // end of add

} // end of debug
</SCRIPT>
</head>
<body>
<script>
var test = {a:1, c:3, b:2};
var testBoolean = true;

// Open the debug window and display debug information
// passing false suppresses all debug information and
// the debug window.
debug(true);

debug.dump(test,"test");
debug.out("display the test object in sorted form");
debug.dumpSorted(test,"test");
debug.out(testBoolean);
debug.out("<b>&<\/b>");

var myString = "abcDEF Ghi~123~ *&^ end";
debug.out("myString = " + myString +
" compressed: " +
escape(myString.match(/[a-zA-Z0-9]/g).join("") ) );

debug.out(
"Display three spaces between words.");
</script>
<p>Debug routines and testing.</p>
</body>
</html>
Jul 23 '05 #8
Abby Lee wrote:
Abby Lee<ab*******@hotmail.com> writes:
http://www.ncsa.uiuc.edu/Divisions/Admin/reimb.asp

[snip]

Do you still need help with this? The page at the link
specified does not seem to have been modified. I could
suggest a number of improvements, but only if it's worth the
effort.

Rob.
Jul 23 '05 #9
On 28 Sep 2004 15:37:46 -0700, Robert <rc*******@my-deja.com> wrote:

[snip]
The function isPosInt returns false for 3.00, but returns true for 2.62.
So it does. It appears that

^0|([1-9]\d*)$

treats the string with

^0 or ([1-9]\d*)$

as opposed to

^0$ or ^([1-9]\d*)$

which was the intention.

Adding extra parentheses repairs it:

function isPosInt(v) {
return /^(0|([1-9]\d*))$/.test(v);
}
Here is a postive real functions:
I think the original objective was for integers only. The acceptance of
some decimal values was an oversight on my part as explained above.
function isPosReal(v) {
var result2 = /^(0|[1-9])\d*\.\d+$/.test(v);
return result2;


Though the intermediate variable is unnecessary.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #10

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

Similar topics

8
by: Ricky Romaya | last post by:
Hi, I'm working on a file upload script. I need to calculate the CRC32 of the file(s) which are successfully uploaded. How can I do this? PHP only have CRC32 function for strings. However, the...
3
by: lawrence | last post by:
If you're doing extensive formatting of output from a database, then you can't ask for all of a type of entry ("SELECT * FROM mainContent") and print it to the screen. On the one hand, it is an...
5
by: Ron Adam | last post by:
Hi, I'm having fun learning Python and want to say thanks to everyone here for a great programming language. Below is my first Python program (not my first program) and I'd apreciate any...
4
by: The Bit Bandit | last post by:
Hopefully someone can help me create a query that I'm having some trouble with. I have three tables: invoices, invoicedetails, invoicepayments The fields are: invoices -------- InvoiceNo
4
by: oshanahan | last post by:
Does anyone have ideas on the best way to move large amounts of data between tables? I am doing several simple insert/select statements from a staging table to several holding tables, but because...
5
by: Julia Baresch | last post by:
Hi everyone, I haven't found any reference to this problem on this group or in Access 97 help. I hope someone here knows this - probably a simple thing, but not obvious. I designed a query to...
0
by: Marina | last post by:
Access 2002: I have an Accounts form that allows the user to enter billing anounts and payment amounts that will then be added to a transaction table. This table is used for the Accounts...
38
by: jdcrief | last post by:
Complier: Visual C++ 2005 Express Edition The program I wrote will compile and execute, but the output is always the same, no matter what number is entered in for the radius of the circle. ...
25
by: Umesh | last post by:
i want to calculate the time required to execute a program. Also i want to calcute the time remaining for the execution of the program. how can i do that? pl mention some good websites for...
28
by: CindySue | last post by:
I found something similar, but can't get it to work--maybe because I'm working in a report rather than a query? I have a main report that has three subreports in it. Each subreport has a total for...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.