473,396 Members | 1,760 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,396 software developers and data experts.

function only works on last row

You all have been much help with my javascript needs...but I need you
again.

Mike gave me this...to add up any of the 7 columns that are changed.
function autoReimb(val, itm) {
var e = document.forms[0].elements,
r = 'autoReimb' + itm,
t = 0;
if(isPosInt(val.value)) {
e[r].value = format(val.value * 0.375);
for(var i = 1; i <= 7; ++i) {
if(isPosInt(e['miles' + i].value)) {
t += +e['autoReimb' + i].value;
}
}
e['autotot'].value = format(t);
lineTotal(val,itm); <-- I added
} else {
e[r].value = '';
}
} //End Function

I added the function call to lineTotal(val,itm) in order to total the
row...which is also changed when the column was changed.

function lineTotal(val, itm){
var e = document.forms[0].elements,
trvtps = new Array('autoReimb','airRail','car','taxi','lodge',' meals','misc');
if(isPosInt(val.value)){
t = 0;
for (var i = 0; i < trvtps.length; i++){
var trvitem = trvtps[i];
if(isPosInt(e[trvitem + itm].value)){
t += +e[trvitem + itm].value;
}
}
e['total' + itm].value = format(t);
}
}

Problem is this only works on the last row...and I don't understand
why. I turned my last row into a remark line and then the row above it
which was not the last line worked great but the others did not add up
correctly.
Jul 23 '05 #1
7 1238

"Abby Lee" <ab*******@hotmail.com> wrote in message
news:80*************************@posting.google.co m...

Both functions are sharing the global variable 't'.
Declare variables with the 'var' keyword.

--
Stephen Chalmers

Jul 23 '05 #2
On Wed, 8 Sep 2004 22:16:04 +0100, Stephen Chalmers
<No*******************@mail.com> wrote:
"Abby Lee" <ab*******@hotmail.com> wrote in message
news:80*************************@posting.google.co m...

Both functions are sharing the global variable 't'.
Declare variables with the 'var' keyword.


Only the lineTotal function declares a global variable, t. The declaration
of t in autoReimb is part of the var statement (notice commas, not
semi-colons).

Abby, could you show a sample of the HTML (a URL, preferably)? It might
shed some light.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3
> Abby, could you show a sample of the HTML (a URL, preferably)? It might
shed some light.

Mike


Took some doing (students only have access to the internal servers).

You can see that if someone enters milage that part works fine...and I
plan to make a simular function for each column. However the rows also
must add up...

The page
http://www.ncsa.uiuc.edu/Divisions/Admin/reimb.asp
My javascript page
http://www.ncsa.uiuc.edu/Divisions/Admin/reimb.js
Jul 23 '05 #4
ab*******@hotmail.com (Abby Lee) writes:
Abby, could you show a sample of the HTML (a URL, preferably)? It might
shed some light.

Mike


Took some doing (students only have access to the internal servers).

You can see that if someone enters milage that part works fine...and I
plan to make a simular function for each column. However the rows also
must add up...

The page
http://www.ncsa.uiuc.edu/Divisions/Admin/reimb.asp
My javascript page
http://www.ncsa.uiuc.edu/Divisions/Admin/reimb.js


Forget the reimb.js file...I just put the javascript code into the .asp file
to make for easy viewing.
thanks.
Jul 23 '05 #5
On 9 Sep 2004 06:35:21 -0700, Abby Lee <ab*******@hotmail.com> wrote:

[snip]
Took some doing (students only have access to the internal servers).


And I believe it paid off. After a quick glance, it seems that the problem
is the relationship between the id and name attributes in the HTML. Whilst
the attributes don't have to match[1], you shouldn't use an id that
matches a name on another control. The reason is that when you look up an
element, ids are checked first, then names if a match wasn't found. So,
when you use

document.forms['formName'].elements['elementName']

You're expecting to find a control named elementName. What's actually
happening though is you're finding a control with the id, elementName.

By the way, consider using regular expressions to validate inputs. Your
validation routines are far more complicated than they need to be.

Mike
[1] In the case of things like multiple, grouped checkboxes, they must not
otherwise you'd have non-unique ids.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #6
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message news:<opseb3ji06x13kvk@atlantis>...
On 9 Sep 2004 06:35:21 -0700, Abby Lee <ab*******@hotmail.com> wrote:

[snip]
Took some doing (students only have access to the internal servers).


And I believe it paid off. After a quick glance, it seems that the problem
is the relationship between the id and name attributes in the HTML. Whilst
the attributes don't have to match[1], you shouldn't use an id that
matches a name on another control. The reason is that when you look up an
element, ids are checked first, then names if a match wasn't found. So,
when you use

document.forms['formName'].elements['elementName']

You're expecting to find a control named elementName. What's actually
happening though is you're finding a control with the id, elementName.

I think I understand what you are saying but am unable to see how to
make it work in my function.

function lineTotal(val, itm){
var ea=document.forms[0].elements['elementName'],
trvtps = new Array('autoReimb','airRail','car','taxi','lodge',' meals','misc');
if(isPosInt(val.value)){
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);
}
}
Jul 23 '05 #7
On 15 Sep 2004 07:23:39 -0700, Abby Lee <ab*******@hotmail.com> wrote:
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:<opseb3ji06x13kvk@atlantis>...
On 9 Sep 2004 06:35:21 -0700, Abby Lee <ab*******@hotmail.com> wrote:

[snip]
> Took some doing (students only have access to the internal servers).


And I believe it paid off. After a quick glance, it seems that the
problem
is the relationship between the id and name attributes in the HTML.
Whilst
the attributes don't have to match[1], you shouldn't use an id that
matches a name on another control. The reason is that when you look up
an
element, ids are checked first, then names if a match wasn't found. So,
when you use

document.forms['formName'].elements['elementName']

You're expecting to find a control named elementName. What's actually
happening though is you're finding a control with the id, elementName.

I think I understand what you are saying but am unable to see how to
make it work in my function.


I wasn't suggesting a change to the script, but to the HTML itself. Take
these table elements from your page. They're from two different rows.

<td width="55" rowspan="2">
<div align="center">
<input name="car1" type="text" class="text" id="autoReimb13"
size="8">
</div>
</td>

and

<td rowspan="2">
<div align="center">
<input name="car2" type="text" class="text" id="car1" size="8">
</div>
</td>

The id of the second input element matches the name of the first element.
When you go to look-up the value of the first input element with

document.forms['reim_vouch'].elements['car1'].value

the search will be conducted by id first, with names checked only if no
match has been found. That means that you'll actually get the second input.

Until you correct this, you can't have a working script. I assume that you
just need to remove the id attributes, but I don't know if that will
affect other parts of the page. You'll have to assess the impact.

By the way, I'm not guaranteeing that changing the HTML will ensure
success. The script might need altering afterwards, but first things
first. If I could understand the page, I might be able to offer some
assurances, but I'll be honest and say that it's a nightmare to navigate
without some form of instruction.

[snip]

Mike

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

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

Similar topics

8
by: Börni | last post by:
Hi, Is there a way to provide a default for a function parameter. i tried function func (type, message, obj = "message") but it doesn't seem to work. It seems a bit ugly to make an if/else...
7
by: VPaul | last post by:
I hope I am posting to the correct group for assistance. Please advise me if there is another group I should go to. I am new to this, so I apologize if I don't explain this very well. I do...
7
by: MLH | last post by:
Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date '************************************************************************** ' Accepts a date. Determines month & year of the date....
2
by: Fernando Barsoba | last post by:
Dear all, I have been posting about a problem trying to encrypt certain data using HMAC-SHA1 functions. I posted that my problem was solved, but unfortunately, I was being overly optimistic. I...
16
by: didier.doussaud | last post by:
I have a stange side effect in my project : in my project I need to write "gobal" to use global symbol : .... import math .... def f() : global math # necessary ?????? else next line...
4
by: Kurt | last post by:
I'm using the fConcatChild function posted at http://www.mvps.org/access/modules/mdl0004.htm to return a field from the Many table of a 1:M relationship into a concatenated string. The function...
1
by: Falko Wagner | last post by:
Hi there, I am currently translating a VB 6.0 application to .NET and have the following problem: The data structure I need to pass to a DLL function call has a structure variable inside its...
3
by: Chen ShuSheng | last post by:
HI, I am now study a segment of codes: ------------------------ printf("%p\t",fp); /*add by me*/ fseek(fp, 0L, SEEK_END); /* go to end of file */ printf("%p\t",fp); ...
5
by: Traclo | last post by:
I wrote this function for my introductory programming class in university. It is used to verify that an ISBN is valid. It does this by checking the calculated checksum of the number to the last digit...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
tracyyun
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...
0
agi2029
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,...

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.