quebectech
Messages postés11Date d'inscriptionjeudi 24 novembre 2005StatutMembreDernière intervention28 décembre 2005
-
5 déc. 2005 à 22:33
PetoleTeam
Messages postés3426Date d'inscriptionlundi 26 décembre 2005StatutMembreDernière intervention14 janvier 2011
-
11 janv. 2006 à 13:31
Bonjour ou Bonsoir, dison que moi jai acheter la suite de script sur EZscripting.com. Maintenant que tout est fonctionnel sur mon serveur, , j'essai de faire fonctionner une fonction javascript pour addidionner tout les champs nommé (prix) qui est inscripte sur leurs site web, mais ca ne marche pas. Voici leurs script;
Here's the JavaScript to add up the numeric values of a column (and average them, if you like). If your column contains null values or text, the script treats them as a zero for addition purposes, but doesn't include the zero value when the totals are averaged. All of what I'm posting here will go in your template page.
First of all, here's the contents of a script tag, which you'll need to place inside your HEAD tags:
<script language="javascript">
var cellcounter = 0;
var colValues = new Array(<<#_matches>>);
var colTotals = 0;
var avgCorrector = 0;
var colAvg = 0;
Next, you'll need to build your template so your results are in a table. The first row (<TR>) will have the titles of your columns, then you can add your template tag around the next row to display your results. You'll need to add a little SCRIPT tag inside the cell (<TD>) that you want to add up or average. In the example below, we're going to display the results of "field1" and "field2", but capture the values of "field2" to add up:
Next, you'll add a final row to the bottom of the table (outside of the template tag), where the added values will appear. Note the use of the tag w/ IDs, which is where the calculations will be displayed:
Finally, you'll need to add an onLoad event to your tag, to trigger the script to run once the page loads:
That should do it. Now, as the page loads, each time you get a match, the value is added to a variable array. Once the page is finished loading, the script is launched, which adds the values of the array together. In the example I've placed above, those added values are then averaged. If you only want to display the total, change the "document.getElementById" line in the script to display the "colTotals" variable instead of the "colAvg" variable. Like this: