473,473 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using the DOM to calculate and display averages

http://www.mickweb.com/football/aleague/ratings.html

I can't get this to work in IE5.2 Mac, it seems to choke on assigning a
table cell's innerHTML property.

player.item(player.length-1).innerHTML=av;

I'm attempting to add each player's ratings and calculate his average
rating. Appears to work in Safari 1.0.2, Netscape 7.0, and Firefox 0.9
(all Mac).
Can anyone suggest how I can use the heirarchal(nodal) DOM to accomplish
the same end? Or improve the script? All table elements are in place.
Mick

Full script below:
<script type="text/JavaScript">
onload=function (){
if(document.getElementsByTagName){
rs= document.getElementsByTagName("TR");
r=rs.length;
while(r--){
if(r&1){
rs.item(r).style.backgroundColor="#c3d3d3";
}
}
//trouble begins below
var t=document.getElementById("ratings");// The table
var trs=t.getElementsByTagName("TR");
for(b=2;b<trs.length;b++){// skip the first two rows
var player=trs.item(b).getElementsByTagName("TD");
var z=0,q=0;
if(player.length){
for(x=0;x<player.length;x++){
if(!isNaN(parseFloat(player.item(x).innerHTML))){
z+=(+ player.item(x).innerHTML);// seems to work
q++ ;
}
av=Math.round((z/q)*100)/100;// so far so good
}
player.item(player.length-1).innerHTML=av; // not good
player.item(player.length-1).style.fontWeight="bold";
}
}
}
}
</script>
Jul 23 '05 #1
2 1737


Mick White wrote:

av=Math.round((z/q)*100)/100;// so far so good
}
player.item(player.length-1).innerHTML=av; // not good


You need to insert a text node, in general after removing all child
nodes thus try
function setInnerText (element, innerText) {
if (element.hasChildNodes) {
while (element.hasChildNodes()) {
element.removeChild(element.lastChild);
}
var textNode;
if (document.createTextNode &&
(textNode = document.createTextNode(innerText)))
{
element.appendChild(textNode);
}
}
}

setInnerText(player.item(player.length - 1), av);

But I don't have a Mac here to test what the problem is and whether the
solution above solves that, so try yourself and report back to the group
whether it works.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2
Martin Honnen wrote:
Mick White wrote:

av=Math.round((z/q)*100)/100;// so far so good
}
player.item(player.length-1).innerHTML=av; // not good

function setInnerText (element, innerText) {
if (element.hasChildNodes) {
while (element.hasChildNodes()) {
element.removeChild(element.lastChild);
}
var textNode;
if (document.createTextNode &&
(textNode = document.createTextNode(innerText)))
{
element.appendChild(textNode);
}
}
}

setInnerText(player.item(player.length - 1), av);

But I don't have a Mac here to test what the problem is and whether the
solution above solves that, so try yourself and report back to the group
whether it works.
Works like a charm, Martin. (Camino 0.8, NN7, Safari 1.0.2, Mozilla 1.6,
Firefox 0.9, MS IE5.2 [all mac])
Thanks.
Mick

Jul 23 '05 #3

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

Similar topics

2
by: Jeff Blee | last post by:
I am hoping someone can help me. I am making a Access 97 app for a person and have run up against a problem to do with MS Graph. There is a table that has a number of data elements and a date field...
2
by: memosa | last post by:
Hi, friends: This is my programme (work on Microsoft visual c++) and I have two question . First, I want to say that there is no error but I need a little help. This is a small programme...
3
by: google | last post by:
I'm developing an application for use within my company in Access 2003. I'm new to '03, the application I did for my former employer was in '97. The two applications have similar functionality...
5
by: chaching | last post by:
Please help. The code below will compile and run using the Dev C compiler, but not the Visual C++ 2005 express edition. I need it to run in the express editions. any suggestions? #include...
0
by: cameron | last post by:
I am currently writing a C++ program that has to calculate and display the monthly mortgage payment amount using the amout of the mortgage, the term, and interest rate as input by the user. Next, I...
3
by: ken.ditto | last post by:
I have a database that stores data collected from a variety of instruments (pressure, temperature, flow rate, etc.) everytime there is a 1% change in the value. The Project Manager wants to be...
1
by: HockeyHero | last post by:
I have a simple table containing a datetime field and a number of data fields. I need to develop a stored procedure that will accept two dates as parameters and report back the average daily value...
6
by: omesh | last post by:
hi guys.. i got a problem.. could anyone help me write a program.. the program is as follows:- 2. Solving systems of Linear equations using Iteration: You are required to write a C++ program...
0
by: SuzK | last post by:
I am trying to calculate in VBA in Access 2002 a moving average and update a table with the calculations. Fields in my WeeklyData table are Week Ending (date) ItemNbr (double) Sales Dollars...
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
jinu1996
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...
1
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...
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,...
0
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...
0
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 ...
0
bsmnconsultancy
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...

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.