By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,655 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

calculating amounts very strange thing

P: n/a
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
Share this Question
Share on Google+
9 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.