Précédent   Forum des professionnels en informatique > Webmasters - Développement Web > JavaScript
JavaScript Forum programmation JavaScript. Lire : Cours JavaScript, FAQ JavaScript, Toutes les FAQ JavaScript et Sources JavaScript
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 11/11/2011, 20h52   #1
Invité de passage
 
Inscription : avril 2007
Messages : 32
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 32
Points : 3
Points : 3
Par défaut séparateur des milles

Bonjour,
J'ai un formulaire qui est un convertisseur pour prêt immobilier.

J'aimerais pouvour formater les nombres pour qu'ils séparent les milles ex:
10'000 ou 100'000 ou comme ca si c'est plus facile 100 000.

voici le code de ma page merci d'avance pour votre aide. là je sèche

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<script language='JavaScript'>
<!--------------------------------------------------------------------
    Memory  = "0";      // initialise memory variable
    Current = "0";      //   and value of Display ("current" value)
    Operation = 0;      // Records code for eg * / etc.
    MAXLENGTH = 30;     // maximum number of digits before decimal!
 
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
 
function insertNthChar(string,chr,nth) {
  var output = '';
  for (var i=0; i<string.length; i++) {
    if (i>0 && i%4 == 0)
      output += chr;
    output += string.charAt(i);
  }
 
  return output;
}
 
 
function Calculate() { 
  Current = document.Calculator.Bien.value;
  Current = eval(((Current * 0.8)*0.0725)/0.33)
  Operation = 0;
  Current = Current + "";
  if (Current.indexOf("Infinity") != -1) {
    Current = "Valeur trop grande";
  };
  if (Current.indexOf("NaN") != -1) {
    Current = "Valeur incorrecte";
  };
  Operation = 0;                //clear operation
  Memory    = "0";              //clear memory
  Current = Math.round(Current);
  document.Calculator.Salaire.value = Current;
}
 
function Calculate2() { 
  Current = document.Calculator.Salaire.value;
  Current = eval((((Current/3)/0.0725)/0.8)*1)
  Operation = 0;
  Current = Current + "";
  if (Current.indexOf("Infinity") != -1) {
    Current = "Valeur trop grande";
  };
  if (Current.indexOf("NaN") != -1) {
    Current = "Valeur incorrecte";
  };
  Operation = 0;                //clear operation
  Memory    = "0";              //clear memory
  Current = Math.round(Current);
  document.Calculator.Bien.value = Current;
}
 
function FixCurrent() {
  Current = document.Calculator.Salaire.value;
  if (Current.indexOf("NaN") != -1) {
    Current = "Valeur incorrecte";
  };
  document.Calculator.Salaire.value = Current;
}
 
function FixCurrent2() {
  Current = document.Calculator.Bien.value;
  if (Current.indexOf("NaN") != -1) {
    Current = "Valeur incorrecte";
  };
  document.Calculator.Bien.value = Current;
 
}
 
//--------------------------------------------------------------->
</script>
 
</head>
 
<body>
 
<form name="Calculator">
<table width="398" id="calcul">
<tbody>
<tr>
  <td width="6">&nbsp;</td>
<td width="163">Salaire brut annuel:</td>
<td width="16">&nbsp;</td>
<td width="193">Prix du bien:</td>
</tr>
<tr>
  <td>&nbsp;</td>
<td><input name="Salaire" type="text" class="contactform" size="20" maxlength="40" />
</td>
<td>&nbsp;</td>
<td><input class="contactform" maxlength="40" name="Bien" size="20" type="text" />
</td>
</tr>
<tr>
  <td>&nbsp;</td>
<td><input onclick="Calculate2()" name="result" type="button" value=" Calcul prix du bien " /></td>
<td>&nbsp;</td>
<td><input onclick="Calculate()" name="result2" type="button" value=" Calcul du salaire " /></td>
</tr>
</tbody>
</table>
</form>
doublemetre est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/11/2011, 22h30   #2
Membre Expert
 
Avatar de Willpower
 
Homme Boris Dessy
sans emploi
Inscription : décembre 2010
Messages : 871
Détails du profil
Informations personnelles :
Nom : Homme Boris Dessy
Localisation : Belgique

Informations professionnelles :
Activité : sans emploi

Informations forums :
Inscription : décembre 2010
Messages : 871
Points : 1 380
Points : 1 380
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* string : $number_format(number $nombre [,string $separateur [,number $longueur]]) */
function number_format(nombre,separateur,longueur){
	/* default values */ 
	separateur = separateur || ",";
	longueur = longueur || 3;
	/* variables */
	var string = nombre.toString(), newString;
	/* split string */
	newString = string.substr(Math.max(string.length-longueur,0),longueur);
	while(string = string.substr(0,string.length-longueur)){
		newString = string.substr(Math.max(string.length-longueur,0),longueur) + separateur + newString;
	}
	/* return new string */
	return newString;
}
/* example */
alert(number_format(1234567890)); // 1,234,567,890
alert(number_format(1234567890,'#',4)); // 12#3456#7890
Willpower est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/11/2011, 23h03   #3
Modérateur
 
Avatar de NoSmoking
 
Homme
Inscription : janvier 2011
Messages : 2 944
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Isère (Rhône Alpes)

Informations forums :
Inscription : janvier 2011
Messages : 2 944
Points : 4 776
Points : 4 776
Bonsoir,
sur base d'une regExp
Code :
1
2
3
4
5
6
7
8
9
10
function formatMillier( nombre){
  nombre += '';
  var sep = ' ';
  var reg = /(\d+)(\d{3})/;
  while( reg.test( nombre)) {
    nombre = nombre.replace( reg, '$1' +sep +'$2');
  }
  return nombre;
}
alert( formatMillier( 100001));
NoSmoking est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/11/2011, 23h03   #4
Expert Confirmé Sénior
 
Avatar de RomainVALERI
 
Homme Romain VALERI
POOête
Inscription : avril 2008
Messages : 2 574
Détails du profil
Informations personnelles :
Nom : Homme Romain VALERI
Âge : 35
Localisation : France, Meurthe et Moselle (Lorraine)

Informations professionnelles :
Activité : POOête

Informations forums :
Inscription : avril 2008
Messages : 2 574
Points : 4 077
Points : 4 077
Par défaut hors-sujet utile : refactorisation

tout est dans le titre ^^

Exemple d'une seule fonction pour remplacer les jumelles FixCurrent et FixCurrent2 :
Code :
1
2
3
4
5
6
7
function FixCurrent(param) {
  Current = document.Calculator[param].value;
  if (Current.indexOf("NaN") != -1) {
    Current = "Valeur incorrecte";
  };
  document.Calculator[param].value = Current;
}
...pour les fonctions Calculate et Calculate2 : même punition

SInon à part ça, ne pas oublier que "eval is evil" !
SURTOUT quand il n'est là que pour ...l'ambiance ^^
La preuve :
Code :
eval((((Current/3)/0.0725)/0.8)*1) == ((((Current/3)/0.0725)/0.8)*1)// true ^^
__________________

...pour les linguistes et les curieux >>> générateur de phrases aléatoires

__________________
RomainVALERI est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/11/2011, 00h55   #5
Invité de passage
 
Inscription : avril 2007
Messages : 32
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 32
Points : 3
Points : 3
J'ai réussi à formater en utilisant une méthode trouvée sur un autre forum :

Mais maintenant mon problème c'est que l'espace est compté et le calcul ne ce fait plu. (je tappe 100 000.00 et résultat est NaN)

voici le code:

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans nom</title>
 
 
 
<script language='JavaScript'>
<!--------------------------------------------------------------------
    Memory  = "0";      // initialise memory variable
    Current = "0";      //   and value of Display ("current" value)
    Operation = 0;      // Records code for eg * / etc.
    MAXLENGTH = 30;     // maximum number of digits before decimal!
 
 
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
 
function insertNthChar(string,chr,nth) {
  var output = '';
  for (var i=0; i<string.length; i++) {
    if (i>0 && i%4 == 0)
      output += chr;
    output += string.charAt(i);
  }
 
  return output;
}
 
 
function Calculate() { 
  Current = document.Calculator.Bien.value;
  Current = eval(((Current * 0.8)*0.0725)/0.33)
  Operation = 0;
  Current = Current + "";
  if (Current.indexOf("Infinity") != -1) {
    Current = "Valeur trop grande";
  };
  if (Current.indexOf("NaN") != -1) {
    Current = "Valeur incorrecte";
  };
  Operation = 0;                //clear operation
  Memory    = "0";              //clear memory
  Current = Math.round(Current);
  document.Calculator.Salaire.value = Current;
}
 
function Calculate2() { 
  Current = document.Calculator.Salaire.value;
  Current = eval((((Current/3)/0.0725)/0.8)*1)
  Operation = 0;
  Current = Current + "";
  if (Current.indexOf("Infinity") != -1) {
    Current = "Valeur trop grande";
  };
  if (Current.indexOf("NaN") != -1) {
    Current = "Valeur incorrecte";
  };
  Operation = 0;                //clear operation
  Memory    = "0";              //clear memory
  Current = Math.round(Current);
  document.Calculator.Bien.value = Current;
}
 
function FixCurrent(param) {
  Current = document.Calculator[param].value;
  if (Current.indexOf("NaN") != -1) {
    Current = "Valeur incorrecte";
  };
  document.Calculator[param].value = Current;
}
 
 
</script>
<script language="JavaScript1.2" src="masks.js"></script>
<script language="JavaScript1.2">
// Mask JavaScript API (v0.3) - dswitzer [chez] pengoworks [point] com - iubito [chez] asp-php [point] net
function init()
{
 
   // Création du masque montant en euro
   oEuroMask = new Mask("#_###.00", "number");
   // Associer le oDateMask aux 2 champs
 
   // Associer le oEuroMask au champ
   oEuroMask.attach(document.Calculator.Salaire);
     oEuroMask.attach(document.Calculator.Bien);
}
 
</script> 
 
</head>
 
<body onload="init();">
<form name="Calculator">
<table width="398" id="calcul">
<tbody>
<tr>
  <td width="6">&nbsp;</td>
<td width="163">Salaire brut annuel:</td>
<td width="16">&nbsp;</td>
<td width="193">Prix du bien:</td>
</tr>
<tr>
  <td>&nbsp;</td>
<td><input name="Salaire" type="text" class="contactform" size="20" maxlength="40" />
</td>
<td>&nbsp;</td>
<td><input class="contactform" maxlength="40" name="Bien" size="20" type="text" />
</td>
</tr>
<tr>
  <td>&nbsp;</td>
<td><input onclick="Calculate2()" name="result" type="button" value=" Calcul prix du bien " /></td>
<td>&nbsp;</td>
<td><input onclick="Calculate()" name="result2" type="button" value=" Calcul du salaire " /></td>
</tr>
</tbody>
</table>
</form>
 
</body>
</html>
doublemetre est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/11/2011, 10h15   #6
Responsable Développement Web

 
Avatar de Bovino
 
Homme Didier Mouronval
Développeur Web
Inscription : juin 2008
Messages : 13 807
Détails du profil
Informations personnelles :
Nom : Homme Didier Mouronval
Âge : 41
Localisation : France, Gironde (Aquitaine)

Informations professionnelles :
Activité : Développeur Web
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : juin 2008
Messages : 13 807
Points : 35 789
Points : 35 789
Beaucoup de choses à redire sur ton code...

<script language="JavaScript1.2">
Je t'invite à te renseigner un peu sur l'attribut language de la balise script.
Il sert à fixer la version de JavaScript à utiliser et est donc particulièrement inutile alors que l'attribut type, lui, est obligatoire !
Se méfier des codes trouvés on ne sait où sur le net et souvent obsolète.
A titre d'analogie, cette syntaxe serait similaire à obliger tes visiteurs à utiliser Internet Explorer 4 (version qui implémente JavaScript 1.2)... Pourquoi pas un message d'alerte "Attention : votre navigateur est beaucoup trop récent !"

Tes variables Operation et Memory ont au moins le mérite d'être jolies, faure d'être utilisées

Current = eval((((Current/3)/0.0725)/0.8)*1)Oh non !!!
Ceci dit, pour aller avec le *1, il ne manquerait pas un petit +0 à la fin ?

Code :
1
2
3
4
5
6
7
8
Current = Current + "";
  if (Current.indexOf("Infinity") != -1) {
    Current = "Valeur trop grande";
  };
  if (Current.indexOf("NaN") != -1) {
    Current = "Valeur incorrecte";
  };
  Current = Math.round(Current);
Il existe les méthodes isFinite() et isNaN() pour tester ça... Ah, quoique, peut-être pas avec JavaScript 1.2
Ensuite, pourquoi transtyper en chaine si c'est pour ensuite retranstyper en nombre (implicite dans Math.round()) ?

Concernant ton problème initial, pourquoi réinventer la roue et ne pas utiliser Number.toLocaleString() ?
Code :
1
2
var nombre = 3500.15;  
alert(nombre.toLocaleString());


Enfin, pour retrouver ensuite le bon nombre :
Code :
1
2
var nombre = '3 500,15';
nombre = nombre.replace(/\s/g, '').replace(/,/, '.');
Souviens toi quand même d'une chose : ne pas copier coller aveuglément des codes sans se demander s'ils sont vraiment à jour et optimisés...
__________________
Pas de question technique par MP !
Tout le monde peut participer à developpez.com, vous avez une idée, contactez-moi !
Vous possédez un blog et aimeriez diffuser vos billets sur le forum, contactez-moi !
Mes formations video2brain : La formation complète sur JavaScriptJavaScript et le DOM par la pratiquePHP 5 et MySQL : les fondamentaux
Mon livre sur jQuery
Bovino est déconnecté   Envoyer un message privé Réponse avec citation 20
Vieux 12/11/2011, 11h18   #7
Invité de passage
 
Inscription : avril 2007
Messages : 32
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 32
Points : 3
Points : 3
Bonjour et merci de prendre du temp pour moi.
Tu me donnes pas mal de pistes, mais le je suis complètement perdu.
Est-ce que tu pourais me donner un coup de main?
Je laisse tombé ce code et repart avec le script d'origine.

celui-là.
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<script language='JavaScript'>
<!--------------------------------------------------------------------
    Memory  = "0";      // initialise memory variable
    Current = "0";      //   and value of Display ("current" value)
    Operation = 0;      // Records code for eg * / etc.
    MAXLENGTH = 30;     // maximum number of digits before decimal!
 
 
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
 
function insertNthChar(string,chr,nth) {
  var output = '';
  for (var i=0; i<string.length; i++) {
    if (i>0 && i%4 == 0)
      output += chr;
    output += string.charAt(i);
  }
 
  return output;
}
 
 
function Calculate() { 
  Current = document.Calculator.Bien.value;
  Current = eval(((Current * 0.8)*0.0725)/0.33)
  Operation = 0;
  Current = Current + "";
  if (Current.indexOf("Infinity") != -1) {
    Current = "Valeur trop grande";
  };
  if (Current.indexOf("NaN") != -1) {
    Current = "Valeur incorrecte";
  };
  Operation = 0;                //clear operation
  Memory    = "0";              //clear memory
  Current = Math.round(Current);
  document.Calculator.Salaire.value = Current;
}
 
function Calculate2() { 
  Current = document.Calculator.Salaire.value;
  Current = eval((((Current/3)/0.0725)/0.8)*1+0)
  Operation = 0;
  Current = Current + "";
  if (Current.indexOf("Infinity") != -1) {
    Current = "Valeur trop grande";
  };
  if (Current.indexOf("NaN") != -1) {
    Current = "Valeur incorrecte";
  };
  Operation = 0;                //clear operation
  Memory    = "0";              //clear memory
  Current = Math.round(Current);
  document.Calculator.Bien.value = Current;
}
 
function FixCurrent(param) {
  Current = document.Calculator[param].value;
  if (Current.indexOf("NaN") != -1) {
    Current = "Valeur incorrecte";
  };
  document.Calculator[param].value = Current;
}
 
 
</script>
</head>
 
<body>
<form name="Calculator">
  <table width="398" id="calcul">
    <tbody>
      <tr>
        <td width="6">&nbsp;</td>
        <td width="163">Salaire brut annuel:</td>
        <td width="16">&nbsp;</td>
        <td width="193">Prix du bien:</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><input name="Salaire" type="text" class="contactform" size="20" maxlength="40" /></td>
        <td>&nbsp;</td>
        <td><input class="contactform" maxlength="40" name="Bien" size="20" type="text" /></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><input onclick="Calculate2()" name="result" type="button" value=" Calcul prix du bien " /></td>
        <td>&nbsp;</td>
        <td><input onclick="Calculate()" name="result2" type="button" value=" Calcul du salaire " /></td>
      </tr>
    </tbody>
  </table>
</form>
</body>
</html>
J'ai essayé sans le Current = Math.round(Current); mais mon résultat n'est plus arondi il y a une virgule
doublemetre est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/11/2011, 11h51   #8
Expert Confirmé Sénior
 
Avatar de RomainVALERI
 
Homme Romain VALERI
POOête
Inscription : avril 2008
Messages : 2 574
Détails du profil
Informations personnelles :
Nom : Homme Romain VALERI
Âge : 35
Localisation : France, Meurthe et Moselle (Lorraine)

Informations professionnelles :
Activité : POOête

Informations forums :
Inscription : avril 2008
Messages : 2 574
Points : 4 077
Points : 4 077
Citation:
Envoyé par doublemetre Voir le message
J'ai essayé sans le Current = Math.round(Current); mais mon résultat n'est plus arondi il y a une virgule
Ce que t'expliquait Bovino plus haut, c'est que tu transformes un nombre en chaine pour le retransformer en nombre donc tu peux supprimer ces deux étapes ^^ mais si tu as effectivement besoin d'arrondir, évidemment tu laisses ton Math.round :
Code :
1
2
3
if (!isFinite(Current)) Current = "Valeur trop grande";
if (isNan(Current)) Current = "Valeur incorrecte";
Current = Math.round(Current);
D'autre part, la version refactorisée que je t'ai proposée ne marchera que si tu adaptes évidemment les appels à cette fonction : ils ne sont pas présents dans les extraits que tu as fournis, montre-les nous si tu veux un coup de main mais ça va être du genre :
Code :
1
2
3
//FixCurrent();
FixCurrent("Salaire");// ou bien
FixCurrent(this.name);//à adapter en fonction de l'endroit où est fait l'appel
Et enfin comme je te le disais tu n'as pas besoin de deux fonctions siamoises non plus pour Calculate :
Code :
1
2
3
4
5
6
7
8
9
10
11
function Calculate(param1, param2) { 
   Current = document.Calculator[param1].value;
   Current = ((Current * 0.8) * 0.0725) / 0.33;
   Operation = 0;
   if (!isFinite(Current)) Current = "Valeur trop grande";
   if (isNan(Current)) Current = "Valeur incorrecte";
   Current = Math.round(Current);
   Operation = 0;                //clear operation
   Memory    = "0";              //clear memory
   document.Calculator[param2].value = Current;
}
en adaptant les appels de cette façon :
Code html :
1
2
3
        <td><input onclick="Calculate('Salaire', 'Bien')" name="result" type="button" value=" Calcul prix du bien " /></td>
        <td>&nbsp;</td>
        <td><input onclick="Calculate('Bien', 'Salaire')" name="result2" type="button" value=" Calcul du salaire " /></td>
__________________

...pour les linguistes et les curieux >>> générateur de phrases aléatoires

__________________
RomainVALERI est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/11/2011, 12h01   #9
Invité de passage
 
Inscription : avril 2007
Messages : 32
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 32
Points : 3
Points : 3
J'ai changé ce que tu m'as indiqué, mais le calcul ne se fait plu.

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans nom</title>
<script language='JavaScript'>
<!--------------------------------------------------------------------
    Memory  = "0";      // initialise memory variable
    Current = "0";      //   and value of Display ("current" value)
    Operation = 0;      // Records code for eg * / etc.
    MAXLENGTH = 30;     // maximum number of digits before decimal!
 
 
function gup( name )
{
 /* name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");*/
   name = name.replace(/\s/g, '').replace(/,/, '.');
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
 
function insertNthChar(string,chr,nth) {
  var output = '';
  for (var i=0; i<string.length; i++) {
    if (i>0 && i%4 == 0)
      output += chr;
    output += string.charAt(i);
  }
 
  return output;
}
 
function Calculate(param1, param2) { 
   Current = document.Calculator[param1].value;
   Current = ((Current * 0.8) * 0.0725) / 0.33;
   Operation = 0;
   if (!isFinite(Current)) Current = "Valeur trop grande";
   if (isNan(Current)) Current = "Valeur incorrecte";
   Current = Math.round(Current);
   Operation = 0;                //clear operation
   Memory    = "0";              //clear memory
   document.Calculator[param2].value = Current;
}
 
function FixCurrent(param) {
  Current = document.Calculator[param].value;
  if (Current.indexOf("NaN") != -1) {
    Current = "Valeur incorrecte";
  };
  document.Calculator[param].value = Current;
}
 
</script>
</head>
 
<body onload="init();">
<form name="Calculator">
  <table width="398" id="calcul">
    <tbody>
      <tr>
        <td width="6">&nbsp;</td>
        <td width="163">Salaire brut annuel:</td>
        <td width="16">&nbsp;</td>
        <td width="193">Prix du bien:</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><input name="Salaire" type="text" class="contactform" size="20" maxlength="40" /></td>
        <td>&nbsp;</td>
        <td><input class="contactform" maxlength="40" name="Bien" size="20" type="text" /></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><input onclick="Calculate('Salaire', 'Bien')" name="result" type="button" value=" Calcul prix du bien " /></td>
        <td>&nbsp;</td>
        <td><input onclick="Calculate('Bien', 'Salaire')" name="result2" type="button" value=" Calcul du salaire " /></td>
      </tr>
    </tbody>
  </table>
</form>
</body>
</html>


Ok tu veux le masks.js ?

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
//Mask JavaScript API (v0.3) - dswitzer [at] pengoworks [dot] com
//http://www.pengoworks.com/workshop/js/mask/
//
//Some new features by Sylvain Machefert - http://iubito.free.fr
 
function _MaskAPI()
{
	this.version = "0.3";
	this.instances = 0;
	this.objects = {};
}
MaskAPI = new _MaskAPI();
 
function Mask(m, t)
{
	this.mask = m;
	this.type = (typeof t == "string") ? t : "string";
	if (this.type == "date")
	{
		// Replace french letters a=année/j=jour by y=year/d=day
		// jj/mm/aaaa => dd/mm/yyyy
		var reg = new RegExp("a", "g");
		this.mask = this.mask.replace(reg, "y");
		var reg2 = new RegExp("j", "g");
		this.mask = this.mask.replace(reg2, "d");
	}
	this.error = [];
	this.errorCodes = [];
	this.value = "";
	this.strippedValue = "";
	this.allowPartial = false;
	this.id = MaskAPI.instances++;
	this.ref = "MaskAPI.objects['" + this.id + "']";
	MaskAPI.objects[this.id] = this;
}
 
Mask.prototype.attach = function (o)
{
	if ((o.readonly == null) || (o.readonly == false))
	{
		o.onkeydown = new Function("return " + this.ref + ".isAllowKeyPress(event, this)");
		o.onkeyup = new Function("return " + this.ref + ".getKeyPress(event, this)");
		o.onblur = new Function("this.value = " + this.ref + ".format(this.value)");
	}
}
 
Mask.prototype.isAllowKeyPress = function (e, o)
{
	if( this.type != "string" ) return true;
	var xe = new xEvent(e);
 
	if( ((xe.keyCode > 47) && (o.value.length >= this.mask.length)) && !xe.ctrlKey ) return false;
	return true;
}
 
Mask.prototype.getKeyPress = function (e, o, _u)
{
	this.allowPartial = true;
	var xe = new xEvent(e);
 
//	var k = String.fromCharCode(xe.keyCode);
 
	if( (xe.keyCode > 47) || (_u == true) || (xe.keyCode == 8 || xe.keyCode == 46) ){
		var v = o.value, d;
		if( xe.keyCode == 8 || xe.keyCode == 46 ) d = true;
		else d = false
 
		if( this.type == "number" ) this.value = this.setNumber(v, d);
		else if( this.type == "date" ) this.value = this.setDateKeyPress(v, d);
		else this.value = this.setGeneric(v, d);
 
		o.value = this.value;
	}
 
	this.allowPartial = false;
	return true;
}
 
Mask.prototype.format = function (s)
{
	if( this.type == "number" ) this.value = this.setNumber(s);
	else if( this.type == "date" ) this.value = this.setDate(s);
	else this.value = this.setGeneric(s);
	return this.value;
}
 
Mask.prototype.throwError = function (c, e, v)
{
//	alert(e);
//	une_variable = e;
//	document.formulaire.inputhidden.value = e;
	document.frmExample.erreur.value = e;
	this.error[this.error.length] = e;
	this.errorCodes[this.errorCodes.length] = c;
	if( typeof v == "string" ) return v;
	return true;
}
 
// ************************ GENERIC *********************** //
 
Mask.prototype.setGeneric = function (_v, _d){
	var v = _v, m = this.mask;
	var r = "x#*", rt = [], nv = "", t, x, a = [], j=0, rx = {"x": "A-Za-z", "#": "0-9", "*": "A-Za-z0-9" };
 
	// strip out invalid characters
	v = v.replace(new RegExp("[^" + rx["*"] + "]", "gi"), "");
	if( (_d == true) && (v.length == this.strippedValue.length) ) v = v.substring(0, v.length-1);
	this.strippedValue = v;
	var b=[];
	for( var i=0; i < m.length; i++ ){
		// grab the current character
		x = m.charAt(i);
		// check to see if current character is a mask, escape commands are not a mask character
		t = (r.indexOf(x) > -1);
		// if the current character is an escape command, then grab the next character
		if( x == "!" ) x = m.charAt(i++);
		// build a regex to test against
		if( (t && !this.allowPartial) || (t && this.allowPartial && (rt.length < v.length)) ) rt[rt.length] = "[" + rx[x] + "]";
		// build mask definition table
		a[a.length] = { "char": x, "mask": t };
	}
 
	var hasOneValidChar = false;
	// if the regex fails, return an error
	if( !this.allowPartial && !(new RegExp(rt.join(""))).test(v) ) return this.throwError(1, "The value \"" + _v + "\" must be in the format " + this.mask + ".\n\nLa valeur \""+_v+"\" doit être dans le format "+this.mask+".", _v);
	// loop through the mask definition, and build the formatted string
	else if( (this.allowPartial && (v.length > 0)) || !this.allowPartial ){
		for( i=0; i < a.length; i++ ){
			if( a[i].mask ){
				while( v.length > 0 && !(new RegExp(rt[j])).test(v.charAt(j)) ) v = (v.length == 1) ? "" : v.substring(1);
				if( v.length > 0 ){
					nv += v.charAt(j);
					hasOneValidChar = true;
				}
				j++;
			} else nv += a[i]["char"];
			if( this.allowPartial && (j > v.length) ) break;
		}
	}
 
	if( this.allowPartial && !hasOneValidChar ) nv = "";
 
	return nv;
}
 
// ************************ NUMBERS *********************** //
 
Mask.prototype.setNumber = function(_v, _d){
	var v = String(_v).replace(/[^\d.-]*/gi, ""), m = this.mask;
	// make sure there's only one decimal point
	v = v.replace(/\./, "d").replace(/\./g, "").replace(/d/, ".");
 
	// check to see if an invalid mask operation has been entered
	if( !/^[\$€%£¥]?((\$?[\+-]?([0#]{1,3}(,|\ |\*|_))?[0#]*(\.[0#]*)?)|([\+-]?\([\+-]?([0#]{1,3}(,|\ |\*|_))?[0#]*(\.[0#]*)?\)))[\$€%£¥]?$/.test(m) )
		return this.throwError(1, "An invalid mask was specified for the \nMask constructor.\n\nUn masque in valide a été défini dans le constructeur", _v);
 
	if( (_d == true) && (v.length == this.strippedValue.length) ) v = v.substring(0, v.length-1);
 
	if( this.allowPartial && (v.replace(/[^0-9]/, "").length == 0) ) return v;
	this.strippedValue = v;
 
	if( v.length == 0 ) v = NaN;
	var vn = Number(v);
	if( isNaN(vn) ) return this.throwError(2, "The value entered was not a number.\n\nLa valeur entrée n'est pas un nombre.", _v);
 
	// if no mask, stop processing
	if( m.length == 0 ) return v;
 
	// get the value before the decimal point
	var vi = String(Math.abs((v.indexOf(".") > -1 ) ? v.split(".")[0] : v));
	// get the value after the decimal point
	var vd = (v.indexOf(".") > -1) ? v.split(".")[1] : "";
	var _vd = vd;
 
	var isNegative = ((Math.abs(vn)*-1 == vn) && (Math.abs(vn) != 0));
 
	// check for masking operations
	var show = {
		"¥" : (m.indexOf("¥") != -1), // Japanese yen
		"£" : (m.indexOf("£") != -1), // English Pound
 
		"$" : (m.indexOf("$") != -1), // /^[\$]/.test(m), // Dollar
		"%" : (m.indexOf("%") != -1), // Percentage
		"(" : (isNegative && (m.indexOf("(") > -1)),
		"+" : ( (m.indexOf("+") != -1) && !isNegative )
	}
	show["-"] = (isNegative && (!show["("] || (m.indexOf("-") != -1)));
	// if mask contain more than one symbol ¥ € $ and %, select just one
	if (show["¥"] && ( show["£"] || show["€"] || show["$"] || show["%"] )) show["¥"] = false;
	if (show["£"] && ( show["€"] || show["$"] || show["%"] )) show["£"] = false;
	if (show["€"] && ( show["$"] || show["%"] )) show["€"] = false;
	if (show["$"] && show["%"]) show["$"] = false;
 
 
	// replace all non-place holders from the mask
	m = m.replace(/[^#0._,]*/gi, "");
 
	/*
		make sure there are the correct number of decimal places
	*/
	// get number of digits after decimal point in mask
	var dm = (m.indexOf(".") > -1 ) ? m.split(".")[1] : "";
	if( dm.length == 0 ){
		vi = String(Math.round(Number(vi)));
		vd = "";
	} else {
		// find the last zero, which indicates the minimum number
		// of decimal places to show
		var md = dm.lastIndexOf("0")+1;
		//In this algorithm, we consider #.000 mask, and we consider we add a '9' after to test the round.
		//123.0456 => 123.46 that's incorrect !
		//So count the number of 0 at the beginning of vd (decimal value)
		var nb0vd = 0;
		var zeros = "";
		while (nb0vd<=vd.length && vd.substring(nb0vd,1)=="0") {
			nb0vd++; zeros += "0";
		}
 
		// if the number of decimal places is greater than the mask, then round off
		if( vd.length > dm.length )
		{
			vd = zeros + String(Math.round(Number(vd.substring(0, dm.length + 1))/10));
			//Sometimes we get 12.997 12.998 12.999 12.1000 so remove the first number and add it to vi (integer value)
			if (vd.length > dm.length) {
				addtovi = vd.substring(0,1); //Get the first number
				vd = vd.substring(1,vd.length); //Remove this first number from vd
				vi = String(Number(vi) + Number(addtovi));
			}
			//And now 12.000 12.001 12.01 so we pad with 0 at the left because we expected 12.002
			while( vd.length < md ) vd = "0" + vd;
		}
		// otherwise, pad the string w/the required zeros
		else while( vd.length < md ) vd += "0";
	}
 
	/*
		pad the int with any necessary zeros
	*/
	// get number of digits before decimal point in mask
	var im = (m.indexOf(".") > -1 ) ? m.split(".")[0] : m;
	im = im.replace(/[^0#]+/gi, "");
	// find the first zero, which indicates the minimum length
	// that the value must be padded w/zeros
	var mv = im.indexOf("0")+1;
	// if there is a zero found, make sure it's padded
	if( mv > 0 ){
		mv = im.length - mv + 1;
		while( vi.length < mv ) vi = "0" + vi;
	}
 
 
	/*
		check to see if we need commas in the thousands place holder
	*/
	//OLD: if( /[#0]+,[#0]{3}/.test(m) ){
	if( /[#0]+(_|,)[#0]{3}/.test(m) ){
		// add the commas (or a space) as the place holder
		//added by Sylvain Machefert: we can define _ symbol to replace comma with space (French notation)
		//so mask = #,###.00 => 1,234,567.89
		//   mask = #_###.00 => 1 234 567.89
		var x = [], i=0, n=Number(vi);
		while( n > 999 ){
			x[i] = "00" + String(n%1000);
			x[i] = x[i].substring(x[i].length - 3);
			n = Math.floor(n/1000);
			i++;
		}
		x[i] = String(n%1000);
		vi = x.reverse().join((m.substring(1,2)).replace("_"," "));//",");
	}
 
 
	/*
		combine the new value together
	*/
	if( (vd.length > 0 && !this.allowPartial) || ((dm.length > 0) && this.allowPartial && (v.indexOf(".") > -1) && (_vd.length >= vd.length)) ){
		v = vi + "." + vd;
	} else if( (dm.length > 0) && this.allowPartial && (v.indexOf(".") > -1) && (_vd.length < vd.length) ){
		v = vi + "." + _vd;
	} else {
		v = vi;
	}
 
	if( show["¥"] ) v = v + "¥";
	if( show["£"] ) v = "£" + v;
	if( show["€"] ) v = "€ " + v; // this.mask.replace(/(^[€])(.+)/gi, "€ ") + v;
	if( show["$"] ) v = "$" + v; // this.mask.replace(/(^[\$])(.+)/gi, "$ ") + v;
	if( show["%"] ) v = v + " %";
	if( show["+"] ) v = "+" + v;
	if( show["-"] ) v = "-" + v;
	if( show["("] ) v = "(" + v + ")";
	return v;
}
 
// ************************ DATES *********************** //
 
Mask.prototype.setDate = function (_v)
{
	var v=_v, m=this.mask;
	var a,e,mm,dd,yy,x,s;
 
	// split mask into array, to see position of each day, month & year
	a = m.split(/[^mdy]+/);
	// split mask into array, to get delimiters
	s = m.split(/[mdy]+/);
	// convert the string into an array in which digits are together
	e = v.split(/[^0-9]/);
 
	if(s[0].length == 0) s.splice(0,1);
 
	for(var i=0; i < a.length; i++){
		x = a[i].charAt(0).toLowerCase();
		if(x=="m") mm = parseInt(e[i],10)-1;
		else if(x=="d") dd = parseInt(e[i],10);
		else if(x=="y") yy = parseInt(e[i],10);
	}
 
	// if year is abbreviated, guess at the year
	if(String(yy).length < 3){
		yy = 2000+yy;
		if((new Date()).getFullYear()+20 < yy) yy = yy-100;
	}
 
	// create date object
	var d = new Date(yy,mm,dd);
 
	if(d.getDate() != dd) return this.throwError(1,"An invalid day was entered.\n\nLe jour est incorrect.",_v);
	else if(d.getMonth() != mm) return this.throwError(2,"An invalid month was entered.\n\nLe mois est incorrect.",_v);
 
	var nv="";
 
	for(i=0; i<a.length; i++){
		x = a[i].charAt(0).toLowerCase();
		if(x=="m"){
			mm++;
			if(a[i].length == 2){
				mm = "0"+mm;
				mm = mm.substring(mm.length-2);
			}
			nv += mm;
		} else if(x == "d"){
			if(a[i].length == 2){
				dd = "0" + dd;
				dd = dd.substring(dd.length-2);
			}
			nv += dd;
		} else if(x == "y"){
			if(a[i].length == 2) nv += d.getYear();
			else nv += d.getFullYear();
		}
 
		if(i<a.length-1) nv += s[i];
	}
 
	return nv;
}
 
Mask.prototype.setDateKeyPress = function (_v, _d)
{
	var v = _v, m = this.mask, k = v.charAt(v.length-1);
	var a, e, c, ml, vl, mm = "", dd = "", yy = "", x, p, z;
 
	if( _d == true ){
		while( (/[^0-9]/gi).test(v.charAt(v.length-1)) ) v = v.substring(0, v.length-1);
		if( (/[^0-9]/gi).test(this.strippedValue.charAt(this.strippedValue.length-1)) ) v = v.substring(0, v.length-1);
		if( v.length == 0 ) return "";
	}
 
	// split mask into array, to see position of each day, month & year
	a = m.split(/[^mdy]/);
	// split mask into array, to get delimiters
	s = m.split(/[mdy]/);
	// remove spaces
	v = v.replace(/\s/g,"");
	// convert the string into an array in which digits are together
	e = v.split(/[^0-9]/);
	// position in mask
	p = (e.length > 0) ? e.length-1 : 0;
	// determine what mask value the user is currently entering
	c = a[p].charAt(0);
	// determine the length of the current mask value
	ml = a[p].length;
 
	for( var i=0; i < e.length; i++ ){
		x = a[i].charAt(0).toLowerCase();
		if( x == "m" ) mm = parseInt(e[i], 10)-1;
		else if( x == "d" ) dd = parseInt(e[i], 10);
		else if( x == "y" ) yy = parseInt(e[i], 10);
	}
 
	var nv = "";
	var j=0;
 
	for( i=0; i < e.length; i++ ){
		x = a[i].charAt(0).toLowerCase();
		if( x == "m" ){
			z = ((/[^0-9]/).test(k) && c == "m");
			mm++;
			if( (e[i].length == 2 && mm < 10)
					|| (a[i].length == 2 && c != "m")
					|| (mm > 1 && c == "m")
					|| (z && a[i].length == 2))
			{
//####
				mm = "0" + mm;
				if (mm > 12) //If month > 12, remove the second number 14 => remove 4
					mm = "1";
				else //month is correct, < 12
					mm = mm.substring(mm.length-2);
				if (mm == 0) //if month is "00" remove the 2nd zero, waiting for a number > 0 !
					mm = "0";
			}
			vl = String(mm).length;
			ml = 2;
			nv += mm;
		} else if( x == "d" ){
			z = ((/[^0-9]/).test(k) && c == "d");
			if( (e[i].length == 2 && dd < 10)
					|| (a[i].length == 2 && c != "d")
					|| (dd > 3 && c == "d")
					|| (z && a[i].length == 2)
					)
			{
				dd = "0" + dd;
				if (dd > 31)
					dd = "3";
/*
				if (dd > 31 && (mm in [0,1,3,5,7,8,10,12]))
					dd = "3";//dd.substring(1);
				else if (dd > 30 && (mm in [4,6,9,11]))
					dd = "3";
				else if (dd > 28+((yy%4 == 0 && yy%100 !=0) || yy%400==0 || yy==0) && (mm==2))
					dd = "2";
*/				else
					dd = dd.substring(dd.length-2);
				if (dd == 0)
					dd = "0";
			}
			vl = String(dd).length;
			ml = 2;
			nv += dd;
		} else if( x == "y" ){
			z = ((/[^0-9]/).test(k) && c == "y");
			if( c == "y" ) yy = String(yy);
			else {
				if( a[i].length == 2 ) yy = d.getYear();
				else yy = d.getFullYear();
			}
			if( (e[i].length == 2 && yy < 10) || (a[i].length == 2 && c != "y") || (z && a[i].length == 2) ){
				yy = "0" + yy;
				yy = yy.substring(yy.length-2);
			}
			ml = a[i].length;
			vl = String(yy).length;
			nv += yy;
		}
 
		if( ((ml == vl || z) && (x == c) && (i < s.length)) || (i < s.length && x != c ) ) nv += s[i];
	}
 
	this.strippedValue = (nv == "NaN") ? "" : nv;
 
	return this.strippedValue;
}
 
 
function xEvent(e)
{
	// routine for NS, Opera, etc DOM browsers
	if( window.Event ){
		var isKeyPress = (e.type.substring(0,3) == "key");
 
		this.keyCode = (isKeyPress) ? parseInt(e.which, 10) : 0;
		this.button = (!isKeyPress) ? parseInt(e.which, 10) : 0;
		this.srcElement = e.target;
		this.type = e.type;
		this.x = e.pageX;
		this.y = e.pageY;
		this.screenX = e.screenX;
		this.screenY = e.screenY;
		if( !isKeyPress ){
			if( document.layers ){
				this.altKey = ((e.modifiers & Event.ALT_MASK) > 0);
				this.ctrlKey = ((e.modifiers & Event.CONTROL_MASK) > 0);
				this.shiftKey = ((e.modifiers & Event.SHIFT_MASK) > 0);
				this.keyCode = this.translateKeyCode(this.keyCode);
			} else {
				this.altKey = e.altKey;
				this.ctrlKey = e.ctrlKey;
				this.shiftKey = e.shiftKey;
			}
		}
	// routine for Internet Explorer DOM browsers
	} else {
		e = window.event;
		this.keyCode = parseInt(e.keyCode, 10);
		this.button = e.button;
		this.srcElement = e.srcElement;
		this.type = e.type;
		if( document.all ){
			this.x = e.clientX + document.body.scrollLeft;
			this.y = e.clientY + document.body.scrollTop;
		} else {
			this.x = e.clientX;
			this.y = e.clientY;
		}
		this.screenX = e.screenX;
		this.screenY = e.screenY;
		this.altKey = e.altKey;
		this.ctrlKey = e.ctrlKey;
		this.shiftKey = e.shiftKey;
	}
	if( this.button == 0 ){
		this.setKeyPressed(this.keyCode);
		this.keyChar = String.fromCharCode(this.keyCode);
	}
}
 
// this method will try to remap the keycodes so the keycode value
// returned will be consistent. this doesn't work for all cases,
// since some browsers don't always return a unique value for a
// key press.
xEvent.prototype.translateKeyCode = function (i)
{
	var l = {};
	// remap NS4 keycodes to IE/W3C keycodes
	if( !!document.layers ){
		if( this.keyCode > 96 && this.keyCode < 123 ) return this.keyCode - 32;
		l = {
			96:192,126:192,33:49,64:50,35:51,36:52,37:53,94:54,38:55,42:56,40:57,41:48,92:220,124:220,125:221,
			93:221,91:219,123:219,39:222,34:222,47:191,63:191,46:190,62:190,44:188,60:188,45:189,95:189,43:187,
			61:187,59:186,58:186,
			"null": null
		}
	}
	return (!!l[i]) ? l[i] : i;
}
 
 
// try to determine the actual value of the key pressed
xEvent.prototype.setKP = function (i, s)
{
	this.keyPressedCode = i;
	this.keyNonChar = (typeof s == "string");
	this.keyPressed = (this.keyNonChar) ? s : String.fromCharCode(i);
	this.isNumeric = (parseInt(this.keyPressed, 10) == this.keyPressed);
	this.isAlpha = ((this.keyCode > 64 && this.keyCode < 91) && !this.altKey && !this.ctrlKey);
	return true;
}
 
// try to determine the actual value of the key pressed
xEvent.prototype.setKeyPressed = function (i)
{
	var b = this.shiftKey;
	if( !b && (i > 64 && i < 91) ) return this.setKP(i + 32);
	if( i > 95 && i < 106 ) return this.setKP(i - 48);
 
	switch( i ){
		case 49: case 51: case 52: case 53: if( b ) i = i - 16; break;
		case 50: if( b ) i = 64; break;
		case 54: if( b ) i = 94; break;
		case 55: if( b ) i = 38; break;
		case 56: if( b ) i = 42; break;
		case 57: if( b ) i = 40; break;
		case 48: if( b ) i = 41; break;
		case 192: if( b ) i = 126; else i = 96; break;
		case 189: if( b ) i = 95; else i = 45; break;
		case 187: if( b ) i = 43; else i = 61; break;
		case 220: if( b ) i = 124; else i = 92; break;
		case 221: if( b ) i = 125; else i = 93; break;
		case 219: if( b ) i = 123; else i = 91; break;
		case 222: if( b ) i = 34; else i = 39; break;
		case 186: if( b ) i = 58; else i = 59; break;
		case 191: if( b ) i = 63; else i = 47; break;
		case 190: if( b ) i = 62; else i = 46; break;
		case 188: if( b ) i = 60; else i = 44; break;
 
		case 106: case 57379: i = 42; break;
		case 107: case 57380: i = 43; break;
		case 109: case 57381: i = 45; break;
		case 110: i = 46; break;
		case 111: case 57378: i = 47; break;
 
		case 8: return this.setKP(i, "[backspace]");
		case 9: return this.setKP(i, "[tab]");
		case 13: return this.setKP(i, "[enter]");
		case 16: case 57389: return this.setKP(i, "[shift]");
		case 17: case 57390: return this.setKP(i, "[ctrl]");
		case 18: case 57388: return this.setKP(i, "[alt]");
		case 19: case 57402: return this.setKP(i, "[break]");
		case 20: return this.setKP(i, "[capslock]");
		case 32: return this.setKP(i, "[space]");
		case 91: return this.setKP(i, "[windows]");
		case 93: return this.setKP(i, "[properties]");
 
		case 33: case 57371: return this.setKP(i*-1, "[pgup]");
		case 34: case 57372: return this.setKP(i*-1, "[pgdown]");
		case 35: case 57370: return this.setKP(i*-1, "[end]");
		case 36: case 57369: return this.setKP(i*-1, "[home]");
		case 37: case 57375: return this.setKP(i*-1, "[left]");
		case 38: case 57373: return this.setKP(i*-1, "[up]");
		case 39: case 57376: return this.setKP(i*-1, "[right]");
		case 40: case 57374: return this.setKP(i*-1, "[down]");
		case 45: case 57382: return this.setKP(i*-1, "[insert]");
		case 46: case 57383: return this.setKP(i*-1, "[delete]");
		case 144: case 57400: return this.setKP(i*-1, "[numlock]");
	}
 
	if( i > 111 && i < 124 ) return this.setKP(i*-1, "[f" + (i-111) + "]");
 
	return this.setKP(i);
}
doublemetre est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/11/2011, 13h39   #10
Expert Confirmé Sénior
 
Avatar de RomainVALERI
 
Homme Romain VALERI
POOête
Inscription : avril 2008
Messages : 2 574
Détails du profil
Informations personnelles :
Nom : Homme Romain VALERI
Âge : 35
Localisation : France, Meurthe et Moselle (Lorraine)

Informations professionnelles :
Activité : POOête

Informations forums :
Inscription : avril 2008
Messages : 2 574
Points : 4 077
Points : 4 077
Citation:
Envoyé par RomainVALERI Voir le message
D'autre part, la version refactorisée que je t'ai proposée ne marchera que si tu adaptes évidemment les appels à cette fonction : ils ne sont pas présents dans les extraits que tu as fournis, montre-les nous si tu veux un coup de main mais ça va être du genre :
Code :
1
2
3
//FixCurrent();
FixCurrent("Salaire");// ou bien
FixCurrent(this.name);//à adapter en fonction de l'endroit où est fait l'appel
Tu n'as pas répondu à ça.
Je vois que tu as remplacé directement tes deux fonctions par celle que je proposais, malheureusement tu sembles n'avoir pas compris la remarque que j'ai faite par rapport aux appels à cette fonction, et donc ça ne *peut* pas fonctionner. Je me trompe ?
__________________

...pour les linguistes et les curieux >>> générateur de phrases aléatoires

__________________
RomainVALERI est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 12/11/2011, 16h52   #11
Invité de passage
 
Inscription : avril 2007
Messages : 32
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 32
Points : 3
Points : 3
d'accord mais je ne comprends pas ou les mettre . .
doublemetre est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/11/2011, 17h12   #12
Expert Confirmé Sénior
 
Avatar de RomainVALERI
 
Homme Romain VALERI
POOête
Inscription : avril 2008
Messages : 2 574
Détails du profil
Informations personnelles :
Nom : Homme Romain VALERI
Âge : 35
Localisation : France, Meurthe et Moselle (Lorraine)

Informations professionnelles :
Activité : POOête

Informations forums :
Inscription : avril 2008
Messages : 2 574
Points : 4 077
Points : 4 077
Il doit y avoir, dans le code JS ou dans le code HTML, un ou des morceaux de code servant à "appeler" la fonction définie par les lignes que nous avons modifiées. Dans ce que tu as déjà posté en extrait, ça n'y est pas j'ai déjà cherché. Donc, c'est ailleurs ^^ mais là on est pas devins c'est à toi de jouer

Tu sais faire une recherche sur plusieurs fichiers ? (avec un Notepad++ par exemple tu trouverais en deux secondes en faisant Ctrl-Shift-F et en choisissant le répertoire racine de ton site, sur le mot-clef "FixCurrent")
__________________

...pour les linguistes et les curieux >>> générateur de phrases aléatoires

__________________
RomainVALERI est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/11/2011, 17h14   #13
Invité de passage
 
Inscription : avril 2007
Messages : 32
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 32
Points : 3
Points : 3
Mais j'ai posté tout ma page j'ai rien d'autre.
doublemetre est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/11/2011, 17h17   #14
Expert Confirmé Sénior
 
Avatar de RomainVALERI
 
Homme Romain VALERI
POOête
Inscription : avril 2008
Messages : 2 574
Détails du profil
Informations personnelles :
Nom : Homme Romain VALERI
Âge : 35
Localisation : France, Meurthe et Moselle (Lorraine)

Informations professionnelles :
Activité : POOête

Informations forums :
Inscription : avril 2008
Messages : 2 574
Points : 4 077
Points : 4 077
On accumule les bizarreries, là quand même

C'est en ligne quelque part ? si oui, ça résoud le problème ^^
__________________

...pour les linguistes et les curieux >>> générateur de phrases aléatoires

__________________
RomainVALERI est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/11/2011, 17h20   #15
Invité de passage
 
Inscription : avril 2007
Messages : 32
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 32
Points : 3
Points : 3
Je te remercie vraiment pour ton aide je ne veux pas te déranger plus, mais là je comprends rien, je vais laisser tombé je crois que c'est mieux.
doublemetre est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/11/2011, 18h02   #16
Membre Expert
 
Avatar de Willpower
 
Homme Boris Dessy
sans emploi
Inscription : décembre 2010
Messages : 871
Détails du profil
Informations personnelles :
Nom : Homme Boris Dessy
Localisation : Belgique

Informations professionnelles :
Activité : sans emploi

Informations forums :
Inscription : décembre 2010
Messages : 871
Points : 1 380
Points : 1 380
un bon début serait de commencer par corriger tes balises script comme te l'a suggéré bovino (rien que ça, ça me bloque déjà lors de la lecture) :

Code :
<script language="JavaScript1.2">
->

Code :
<script type="text/javascript">
Willpower est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/11/2011, 19h15   #17
Modérateur
 
Avatar de NoSmoking
 
Homme
Inscription : janvier 2011
Messages : 2 944
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Isère (Rhône Alpes)

Informations forums :
Inscription : janvier 2011
Messages : 2 944
Points : 4 776
Points : 4 776
Citation:
Envoyé par doublemetre Voir le message
Je te remercie vraiment pour ton aide je ne veux pas te déranger plus, mais là je comprends rien, je vais laisser tombé je crois que c'est mieux.
ce serait balot .

comme dit par bovino
mettre en place les espaces ce fait avec
Code :
nombre = nombre.toLocaleString();
et pour faire l'inverse, les supprimer
Code :
nombre = nombre.replace(/\s/g, '').replace(/,/, '.');
La première formule est
Code :
valeur = (( valeur * 0.8) * 0.0725) / 0.33;
la deuxième formule est
Code :
valeur  = (((valeur/3)/0.0725)/0.8)*1;
là je te fait confiance...mais il te faut bien 2 fonctions différentes, ce que tu peux factoriser c'est le test sur la valeur.

Sans oublier de ce remettre conforme à ce qui se fait actuellement pour la déclaration d'une zone script <script type="text/javascript">.
...ton code pourrait devenir
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<script type="text/javascript">
function calculBien( param1, param2){
  var valeur = (document.Calculator[param1].value).replace(/\s/g, '');
  valeur = (( valeur * 0.8) * 0.0725) / 0.33;
  if (!isFinite( valeur)){
    valeur = "Valeur trop grande";
  }
  if( isNaN( valeur)){
    valeur = "Valeur incorrecte";
  }
  document.Calculator[param2].value = Math.round( valeur).toLocaleString();
}
function calculSalaire( param1, param2){
  var valeur = document.Calculator[param1].value.replace(/\s/g, '');
  valeur  = (((valeur/3)/0.0725)/0.8)*1;
  if (!isFinite( valeur)){
    valeur = "Valeur trop grande";
  }
  if( isNaN( valeur)){
    valeur = "Valeur incorrecte";
  }
  document.Calculator[param2].value = Math.round( valeur).toLocaleString();
}
</script>
sans oublier de modifier l'appel aux fonctions dans ton code HTML.

On trouve dans ton code cette ligne
Code :
<body onload="init();">
mais pas de trace de la fonction init(), donc à supprimer.

Voila déjà pour une reprise de confiance.
NoSmoking est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/11/2011, 22h54   #18
Invité de passage
 
Inscription : avril 2007
Messages : 32
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 32
Points : 3
Points : 3
Bonjour et merci pour ton aide j'ai changé voilà ce que j'ai:

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans nom</title>
<script type="text/javascript">
 
    Memory  = "0";      // initialise memory variable
    Current = "0";      //   and value of Display ("current" value)
    Operation = 0;      // Records code for eg * / etc.
    MAXLENGTH = 30;     // maximum number of digits before decimal!
 
 
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
 
function insertNthChar(string,chr,nth) {
  var output = '';
  for (var i=0; i<string.length; i++) {
    if (i>0 && i%4 == 0)
      output += chr;
    output += string.charAt(i);
  }
 
  return output;
}
 
function calculBien( param1, param2){
  var valeur = (document.Calculator[param1].value).replace(/\s/g, '');
  valeur = (( valeur * 0.8) * 0.0725) / 0.33;
  if (!isFinite( valeur)){
    valeur = "Valeur trop grande";
  }
  if( isNaN( valeur)){
    valeur = "Valeur incorrecte";
  }
  document.Calculator[param2].value = Math.round( valeur).toLocaleString();
}
function calculSalaire( param1, param2){
  var valeur = document.Calculator[param1].value.replace(/\s/g, '');
  valeur  = (((valeur/3)/0.0725)/0.8)*1;
  if (!isFinite( valeur)){
    valeur = "Valeur trop grande";
  }
  if( isNaN( valeur)){
    valeur = "Valeur incorrecte";
  }
  document.Calculator[param2].value = Math.round( valeur).toLocaleString();
}
 
 
function FixCurrent(param) {
 
  Current = document.Calculator[param].value;
  if (Current.indexOf("NaN") != -1) {
    Current = "Valeur incorrecte";
  };
  document.Calculator[param].value = Current;
}
 
</script>
</head>
 
<body>
<form name="Calculator">
  <table width="398" id="calcul">
    <tbody>
      <tr>
        <td width="6">&nbsp;</td>
        <td width="163">Salaire brut annuel:</td>
        <td width="16">&nbsp;</td>
        <td width="193">Prix du bien:</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><input name="Salaire" type="text" class="contactform" size="20" maxlength="40" /></td>
        <td>&nbsp;</td>
        <td><input class="contactform" maxlength="40" name="Bien" size="20" type="text" /></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
<td><input onclick="calculSalaire" name="result" type="button" value=" Calcul prix du bien " /></td>
<td>&nbsp;</td>
<td><input onclick="calculBien" name="result2" type="button" value=" Calcul du salaire " /></td>
 
      </tr>
    </tbody>
  </table>
</form>
</body>
</html>
Mais quand je clique sur calcul prix du bien, j'ai rien qui ce passe.
doublemetre est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/11/2011, 23h04   #19
Membre Expert
 
Avatar de Willpower
 
Homme Boris Dessy
sans emploi
Inscription : décembre 2010
Messages : 871
Détails du profil
Informations personnelles :
Nom : Homme Boris Dessy
Localisation : Belgique

Informations professionnelles :
Activité : sans emploi

Informations forums :
Inscription : décembre 2010
Messages : 871
Points : 1 380
Points : 1 380
maintenant que les balises script sont bonnes, je m'arrête à la première instruction :

Code :
<!--------------------------------------------------------------------
n'est pas une instruction javascript !
Willpower est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/11/2011, 23h09   #20
Invité de passage
 
Inscription : avril 2007
Messages : 32
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 32
Points : 3
Points : 3
merci, voilà c'est corrigé

Mais ici je suis juste ?

Code :
1
2
3
<td><input onclick="calculSalaire" name="result" type="button" value=" Calcul prix du bien " /></td>
<td>&nbsp;</td>
<td><input onclick="calculBien" name="result2" type="button" value=" Calcul du salaire " /></td>
doublemetre est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 06h51.


 
 
 
 
Partenaires

Hébergement Web