Calcul instantané

D

DamDamDeo

Bonjour à tous,
je permets ce petit message, ceci afin de soliciter votre aide sur un
petit problème...

Voici mon formulaire (du moins une partie) :

Code:
<body>
<form name="form1" method="post" action=""><table width="389"
border="1">
<table width="46%" border="0" cellspacing="2" cellpadding="0">
<tr>
<td width="29%">&nbsp;</td>
<td width="22%"><div
align="center"><strong>acteur</strong></div></td>
<td width="25%"><div
align="center"><strong>chanteur</strong></div></td>
<td width="24%">total</td>
</tr>
<tr>
<td>Adultes</td>
<td>

<input name="ch_acteur_adultes" type="text"
id="ch_acteur_adultes" size="10" onchange="add()"/[QUOTE]
</td>[/QUOTE]
<td>
<input name="chanteur_adulte" type="text"
id="chanteur_adulte" size="10" onchange="add()"/>                    </
td>
<td><input name="total_adultes" type="text"
id="total_adultes" size="10" style="border:solid 2px  #FF6600"
readonly="true"/></td>
</tr>
<tr>
<td>De 12 &agrave; 18 ans</td>
<td>
<input name="ch_acteur_18" type="text"
id="ch_acteur_18" size="10" onchange="add()"/>                    </
td>
<td>
<input name="chanteur_18" type="text"
id="chanteur_18" size="10" />                    </td>
<td><input name="total_18" type="text"
id="total_18" size="10" style="border:solid 2px  #FF6600"
readonly="true"/></td>
</tr>
<tr>
<td>Moins de 12 ans</td>
<td>
<input name="ch_acteur_12" type="text"
id="ch_acteur_12" size="10" onchange="add()"/>                    </
td>
<td>
<input name="chanteur_12" type="text"
id="chanteur_12" size="10" />                   </td>
<td>
<input name="total_12" type="text" id="total_12"
size="10" style="border:solid 2px  #FF6600" readonly="true"/[QUOTE]
</td>[/QUOTE]
</tr>
<tr>
<td>total</td>
<td><input name="total_acteur" type="text"
id="total_acteur" size="10" style="border:solid 2px  #FF6600"
readonly="true"/></td>
<td><input name="total_chanteur" type="text"
id="total_chanteur" size="10" style="border:solid 2px  #FF6600"
readonly="true"/></td>
<td><input name="total" type="text" id="total"
size="10" style="border:solid 2px  #FF6600" readonly="true"/></td>
</tr>
</table>


</form>





</body>
[code]

Le but de ce formulaire est de calculer le nb d'adhérents pour chaque
catégorie, et pour cela, j'utilise le petit script suivant :

[code]
<script type="text/javascript">
function purge(nbre) {
// conversion séparateur ',' en '.'
nbre = nbre.replace(',','.');
// recherche et remplacement de caractères non désirés
nbre = nbre.replace(/([^0-9 ^.]|\.{2,5}|\s)/g,'');
return nbre;
}
function add() {
var f = document.forms[0];
var tot = 0;
// pour chaque élément du formulaire
for(var i=0; i<f.length; i++) {
// si c'est un champ de texte et dont le nom commence par 'ch_'
if(f[i].type=='text' && f[i].name.indexOf('ch_')>=0) {
// correction du contenu du champ
f[i].value = purge(f[i].value);
// ajout de cette valeur à la variable 'tot'
tot += f[i].value*1;
// comme la valeur d'un champ est de type texte
// on l'a transformée en nombre (en le multipliant par 1)
// avant de faire l'addition
}
}
// insertion du résultat
f['total_acteur'].value = tot;
}
</script>

Mon soucis est que ce script ne me permet pas de faire plusieurs
calculs dans un même formulaire.
Comment remédier à ce soucis qui commence à me hanter depuis plusieurs
jours maintenant.

D'avance merci,
 
R

Richard Cornford

You are very polite, but the language here is English.

No, this is the international javascript newsgroup and so people may
post here in any language they like. The majority of the posts here may
be in English but that is mostly a consequence of there being no
language specific javascript group for English or national groups for
English speaking countries.
I would suggest that if you want help, as you do, you should
ask an English-speaking friend to enter the post for you in
English and to translate the responses into French for you.
That way you will have a much wider audience available to
help you.

It is often the case that a bad translation into English conveys as
little meaning as a post in its original language does for someone who
does not understand that language. It often seems to me that where a
translation into English is to be posted it would be a good idea to
accompany it with the equivalent in the original language, in the hope
that where the translation is poor or ambiguous someone with knowledge
of the original language may be able to improve the translation even if
they cannot directly answer the question in its original language.
I, personally, do not speak French ... .

Neither do I, but this group has at least one French national as a
regular contributor and I bet many others know enough French to make
complaining about its use here unwise.

Richard.
 
B

berzemus

DamDamDeo a écrit :
Bonjour à tous,
je permets ce petit message, ceci afin de soliciter votre aide sur un
petit problème...

Voici mon formulaire (du moins une partie) :

Code:
<body>
<form name="form1" method="post" action=""><table width="389"
border="1">
<table width="46%" border="0" cellspacing="2" cellpadding="0">
<tr>
<td width="29%">&nbsp;</td>
<td width="22%"><div
align="center"><strong>acteur</strong></div></td>
<td width="25%"><div
align="center"><strong>chanteur</strong></div></td>
<td width="24%">total</td>
</tr>
<tr>
<td>Adultes</td>
<td>

<input name="ch_acteur_adultes" type="text"
id="ch_acteur_adultes" size="10" onchange="add()"/[QUOTE]
</td>[/QUOTE]
<td>
<input name="chanteur_adulte" type="text"
id="chanteur_adulte" size="10" onchange="add()"/>                    </
td>
<td><input name="total_adultes" type="text"
id="total_adultes" size="10" style="border:solid 2px  #FF6600"
readonly="true"/></td>
</tr>
<tr>
<td>De 12 &agrave; 18 ans</td>
<td>
<input name="ch_acteur_18" type="text"
id="ch_acteur_18" size="10" onchange="add()"/>                    </
td>
<td>
<input name="chanteur_18" type="text"
id="chanteur_18" size="10" />                    </td>
<td><input name="total_18" type="text"
id="total_18" size="10" style="border:solid 2px  #FF6600"
readonly="true"/></td>
</tr>
<tr>
<td>Moins de 12 ans</td>
<td>
<input name="ch_acteur_12" type="text"
id="ch_acteur_12" size="10" onchange="add()"/>                    </
td>
<td>
<input name="chanteur_12" type="text"
id="chanteur_12" size="10" />                   </td>
<td>
<input name="total_12" type="text" id="total_12"
size="10" style="border:solid 2px  #FF6600" readonly="true"/[QUOTE]
</td>[/QUOTE]
</tr>
<tr>
<td>total</td>
<td><input name="total_acteur" type="text"
id="total_acteur" size="10" style="border:solid 2px  #FF6600"
readonly="true"/></td>
<td><input name="total_chanteur" type="text"
id="total_chanteur" size="10" style="border:solid 2px  #FF6600"
readonly="true"/></td>
<td><input name="total" type="text" id="total"
size="10" style="border:solid 2px  #FF6600" readonly="true"/></td>
</tr>
</table>


</form>





</body>
[code]

Le but de ce formulaire est de calculer le nb d'adhérents pour chaque
catégorie, et pour cela, j'utilise le petit script suivant :

[code]
<script type="text/javascript">
function purge(nbre) {
// conversion séparateur ',' en '.'
nbre = nbre.replace(',','.');
// recherche et remplacement de caractères non désirés
nbre = nbre.replace(/([^0-9 ^.]|\.{2,5}|\s)/g,'');
return nbre;
}
function add() {
var f = document.forms[0];
var tot = 0;
// pour chaque élément du formulaire
for(var i=0; i<f.length; i++) {
// si c'est un champ de texte et dont le nom commence par 'ch_'
if(f[i].type=='text' && f[i].name.indexOf('ch_')>=0) {
// correction du contenu du champ
f[i].value = purge(f[i].value);
// ajout de cette valeur à la variable 'tot'
tot += f[i].value*1;
// comme la valeur d'un champ est de type texte
// on l'a transformée en nombre (en le multipliant par 1)
// avant de faire l'addition
}
}
// insertion du résultat
f['total_acteur'].value = tot;
}
</script>

Mon soucis est que ce script ne me permet pas de faire plusieurs
calculs dans un même formulaire.
Comment remédier à ce soucis qui commence à me hanter depuis plusieurs
jours maintenant.

D'avance merci,

Hi, Salut,

The french javascript forum is fr.comp.lang.javascript

Le forum francophone sur javascript est fr.comp.lang.javascript
Tu auras bien plus de chances d'avoir une réponse la-bas.

B.
 
D

Dr J R Stockton

In comp.lang.javascript message <mYidnZ0q66Nr8L7VnZ2dnUVZ_rTinZ2d@gigane
You are very polite, but the language here is English. I would suggest
that if you want help, as you do, you should ask an English-speaking
friend to enter the post for you in English and to translate the
responses into French for you. That way you will have a much wider
audience available to help you.

There is no point in adding to the readership those who are too ill-
educated or stupid to be able to understand the question.

Questions should be asked in the language which is most likely to be
sufficiently well understood, as written, by at least one person who
knows or can readily enough find the answer. For many francophones,
that consideration should rule out any attempt at English. Only
articles intended to publish useful information need to be widely
readable.
I, personally, do not speak French but I could piece together your
introduction. However, I don't know what your problem is.

I can only presume you to be a lower-class American. To avoid
persistently causing offence, you should avoid writing in international
media.
 
E

Evertjan.

sheldonlg wrote on 09 mei 2008 in comp.lang.javascript:
I guess the dr in front of your name nust stand for "damn rude". I
gave a friendly suggestion. There was no call for an attack on your
part. I guess, though, every group has its assholes.

Please inspect your own rudeness by saying that this NG is an
English-speaking NG and thereby discrediting the use and users of French
first.

Because you did not yet, John's presumption could be the more true,
especially since you think it rude, and the foul language you use.
 
J

John W Kennedy

Ivan said:
....uh, I'm a lower-class American and I don't have any problem with french
speakers posting in french.

So why the anti-american BS there doc?

He's been at it for years; evidently, he regards "American" as the
ultimate insult. Sad story, really. Put the whole family fortune into a
Broadway production of "Daisy Pulls it Off". Closing notice went up
before interval. Had to sell the old family seat, Mon Gaspillage, at
Upper-Walloping-on-Bottie, to a Slovenian who had made his fortune in
trade. Telegraph cut off his subscription, and he never found out
whether Alex Masterly got his job back at Megabank.

--
John W. Kennedy
"It may in me be merely prejudice,
The effect of young-opinion deep engraved
Upon the tender mind by care parental;
But I must think your country has mistook
Her interests. Believe me, but for this I should
Not willingly have drawn a sword against her."
-- William Dunlap: "André: a Tragedy in Five Acts" (1798)
 
E

Evertjan.

sheldonlg wrote on 09 mei 2008 in comp.lang.javascript:
Evertjan. wrote:

i just noticed that you are in the Netherlands. My family and I
vacationed there about 20 years ago. It is a marvelous country. We had
a great time in Amsterdam, Volundam, Edam, Gouda (on a Friday at the
cheese fair), Delft and finally visiting Maduradam. (Please excuse the
misspellings).

I excuse your misspelling,
but not your failed quoting,
as I did not write that.
 
A

Arnaud Diederen

DamDamDeo said:
Bonjour à tous,
je permets ce petit message, ceci afin de soliciter votre aide sur un
petit problème...
[snip]

Hi DamDamDeo,

while it is true that it is absolutely permitted to post in french
on this newsgroup, you're indeed more likely to get more help if
you choose to write in english.


[french]

DamDamDeo,

il est tout a fait permis de poster en français dans ce groupe, mais
les probabilités que l'on vous réponde sont relativement minimes.
Je vous conseille par conséquent de poursuivre en anglais, si cela
vous est possible.

[/french]


I'll try and explain DamDamDeo's problem:

- He's got a <form> with many <input> fields in which the user
punches numbers (or something that resembles numbers...)

- He's got a few JavaScript functions that will convert those
values into numbers, sum them up, and then display them in a
dedicated <input> field

The JavaScript functions, commented in english (with the addition
of three "NOTE"s from my side) follow:


------------------------

function purge(nbre) {

// ',' -> '.'
//
// NOTE:
// For those who wouldn't know, in french, the
// decimal part of a number is separated from its
// integer part with a comma, and not a dot.
// --ad Thu May 15 10:53:01 2008
nbre = nbre.replace(',','.');

// in case the value of the <input> was not a
// proper representation of a number, try and convert
// some of its "unwanted" characters into something else,
// (e.g., removing white spaces, ... ) so that, in the end,
// the string is a valid representation of a number
//
// NOTE: I personally tend to think that those heuristics
// are not even worth the trouble, and that they sometimes
// do more harm than good.
// --ad Thu May 15 10:53:16 2008
nbre = nbre.replace(/([^0-9 ^.]|\.{2,5}|\s)/g,'');
return nbre;
}

function add() {

var f = document.forms[0];
var tot = 0;

// forEach...
for(var i=0; i<f.length; i++) {

// if <input type="text" name="ch_.*" ...
if(f.type=='text' && f.name.indexOf('ch_')>=0) {

// Patch the <input>'s value with a (hopefully
// valid) number
f.value = purge(f.value);

// convert to number
//
// NOTE: If the derived value is invalid
// (i.e., isNaN(f.value) === true), then
// the "tot" value will be NaN as well.
// --ad Thu May 15 10:53:20 2008
tot += f.value*1;
}
}

// Display total
f['total_acteur'].value = tot;
}

------------------------

DamDamDeo's question is:
Mon soucis est que ce script ne me permet pas de faire plusieurs
calculs dans un même formulaire.
Comment remédier à ce soucis qui commence à me hanter depuis plusieurs
jours maintenant.

My problem is that this script won't allow more than one computation in
the same <form>
How can I do it?

DamDamDeo: What do you want to do, exactly? Do you
want to perform "subtotals" (e.g., the total of the three first <input>
fields values, and then the total of rest)?

[french]

DamDamDeo: Que desirez-vous faire, au juste?
Le but est-il de pouvoir totaliser plusieurs sous-ensembles de valeurs
dans les <input>?
Par example: Le nombre total de participants en dans les trois premiers
<input>, et ensuite le total du reste?

[/french]

Bien à vous,

Arnaud
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top