begin process at 2008 08 28 21:50:37
1 233 393 membres
485 nouveaux aujourd'hui
14 291 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

CALCULATRICE SIMPLE


Information sur la source

Catégorie :Fenêtre & Pop-up Classé sous : calculatrice, popup Niveau : Initié Date de création : 24/06/2006 Date de mise à jour : 25/06/2006 12:34:38 Vu / téléchargé: 8 783 / 513

Note :
Aucune note

Commentaire sur cette source (8)
Ajouter un commentaire et/ou une note

Description

Je sais qu'il y a déja des srcipts pour la calculatrice mais celle-ci est plus simple et on peut l'ouvrir dans une pop-up (pour que le visiteur ait toujours la calculatrice sous la main).

Vous devez créer deux pages, une pour la calculatrice (page 1) et l'autre pour ouvrir cet page dans une pop-up (page 2).

Source

  • // PAGE 1 !
  • <html>
  • <head>
  • <title>Calculatrice Simple</title>
  • <script language="JavaScript">
  • function verification(entree) {
  • var car ="1234567890[]()+-.*,/";
  • for (var i = 0; i < entree.length; i++)
  • if (car.indexOf(entree.charAt(i))<0 ) return false;
  • return true;
  • }
  • function calcul() {
  • var a = 0;
  • if (verification(window.document.calculatrice.result.value))
  • a = eval(window.document.calculatrice.result.value);
  • window.document.calculatrice.result.value = a;
  • }
  • function ajouter(caracteres) {
  • window.document.calculatrice.result.value =
  • window.document.calculatrice.result.value + caracteres;
  • }
  • function fonction_speciale(fonction) {
  • if (verification(window.document.calculatrice.result.value)) {
  • if(fonction == "sqrt") {
  • var a = 0;
  • a = eval(window.document.calculatrice.result.value);
  • window.document.calculatrice.result.value = Math.sqrt(a);
  • }
  • if(fonction == "pow") {
  • var a = 0;
  • a = eval(window.document.calculatrice.result.value);
  • window.document.calculatrice.result.value = a * a;
  • }
  • if(fonction == "log") {
  • var a = 0;
  • a = eval(window.document.calculatrice.result.value);
  • window.document.calculatrice.result.value = Math.log(a);
  • }
  • } else window.document.calculatrice.result.value = 0
  • }
  • </script>
  • </head>
  • <body>
  • <table border bgcolor=#0001cc>
  • <th>
  • <form name="calculatrice">
  • <center>
  • <textarea style="WIDTH: 186px; HEIGHT: 24px; TEXT-ALIGN:right;" name="result" align="right" class="affiche"></textarea><br>
  • <input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b2" value="7" onClick="ajouter('7')" size="30">
  • <input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b3" value="8" onClick="ajouter('8')" size="30">
  • <input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b4" value="9" onClick="ajouter('9')" size="30">
  • <input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b12" value=":" onClick="ajouter('/')" size="30"><br>
  • <input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b5" value="4" onClick="ajouter('4')" size="30">
  • <input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b6" value="5" onClick="ajouter('5')" size="30">
  • <input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b7" value="6" onClick="ajouter('6')" size="30">
  • <input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b11" value="x" onClick="ajouter('*')" size="30"><br>
  • <input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b8" value="1" onClick="ajouter('1')" size="30">
  • <input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b9" value="2" onClick="ajouter('2')" size="30">
  • <input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b10" value="3" onClick="ajouter('3')" size="30">
  • <input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b13" value="-" onClick="ajouter('-')" size="30"><br>
  • <input style="FONT-WEIGHT: bold; WIDTH: 92px; HEIGHT: 24px" type="button" name="b14" value="0" onClick="ajouter('0')" size="30">
  • <input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b15" value="." onClick="ajouter('.')" size="30">
  • <input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b16" value="+" onClick="ajouter('+')" size="30"><br>
  • <input style="FONT-WEIGHT: bold; WIDTH: 140px; HEIGHT: 24px" type="reset" name="b17" value="ON/C" size="30">
  • <input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b18" value="=" onClick="calcul()" size="30"><br>
  • <input style="FONT-WEIGHT: bold; WIDTH: 60px; HEIGHT: 24px" type="button" class="button" value="sqrt " onClick="fonction_speciale('sqrt')">
  • <input style="FONT-WEIGHT: bold; WIDTH: 60px; HEIGHT: 24px" type="button" class="button" value=" pow " onClick="fonction_speciale('pow')">
  • <input style="FONT-WEIGHT: bold; WIDTH: 60px; HEIGHT: 24px" type="button" class="button" value=" log " onClick="fonction_speciale('log')">
  • </center>
  • </form>
  • </th>
  • </table>
  • </body>
  • </html>
  • // PAGE 2 !
  • <html>
  • <head>
  • <title>Calculatrice Simple</title>
  • </head>
  • <body vlink="#0000FF">
  • <p><a href="calcul.htm" target="popup"
  • onmouseover="this.style.color='red'"
  • onmouseout="this.style.color='blue'"
  • onclick="window.open('','popup','width=218,height=215,left=100,top=100,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,status=no')">Calculatrice</a>
  • </p>
  • </body>
  • </html>
// PAGE 1 ! 

<html>
<head>
<title>Calculatrice Simple</title>

<script language="JavaScript">

function verification(entree) {
  var car ="1234567890[]()+-.*,/";
  for (var i = 0; i < entree.length; i++)
   if (car.indexOf(entree.charAt(i))<0 ) return false;
  return true;
 }

 function calcul() {
   var a = 0;
  if (verification(window.document.calculatrice.result.value))
     a = eval(window.document.calculatrice.result.value);
   window.document.calculatrice.result.value = a;
 }

 function ajouter(caracteres) {
   window.document.calculatrice.result.value =
   window.document.calculatrice.result.value + caracteres;
 }

 function fonction_speciale(fonction) {
   if (verification(window.document.calculatrice.result.value)) {
     if(fonction == "sqrt") {
       var a = 0;
     a = eval(window.document.calculatrice.result.value);
     window.document.calculatrice.result.value = Math.sqrt(a);
   }
   if(fonction == "pow") {
     var a = 0;
     a = eval(window.document.calculatrice.result.value);
     window.document.calculatrice.result.value = a * a;
   }
   if(fonction == "log") {
     var a = 0;
     a = eval(window.document.calculatrice.result.value);
     window.document.calculatrice.result.value = Math.log(a);
   }
  } else window.document.calculatrice.result.value = 0
}

</script>
</head>
<body>
<table border bgcolor=#0001cc>
<th>
<form name="calculatrice">
<center>
<textarea style="WIDTH: 186px; HEIGHT: 24px; TEXT-ALIGN:right;" name="result" align="right" class="affiche"></textarea><br>
<input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b2" value="7" onClick="ajouter('7')" size="30">
<input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b3" value="8" onClick="ajouter('8')" size="30">
<input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b4" value="9" onClick="ajouter('9')" size="30">
<input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b12" value=":" onClick="ajouter('/')" size="30"><br>
<input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b5" value="4" onClick="ajouter('4')" size="30">
<input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b6" value="5" onClick="ajouter('5')" size="30">
<input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b7" value="6" onClick="ajouter('6')" size="30">
<input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b11" value="x" onClick="ajouter('*')" size="30"><br>
<input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b8" value="1" onClick="ajouter('1')" size="30">
<input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b9" value="2" onClick="ajouter('2')" size="30">
<input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b10" value="3" onClick="ajouter('3')" size="30">
<input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b13" value="-" onClick="ajouter('-')" size="30"><br>
<input style="FONT-WEIGHT: bold; WIDTH: 92px; HEIGHT: 24px" type="button" name="b14" value="0" onClick="ajouter('0')" size="30">
<input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b15" value="." onClick="ajouter('.')" size="30">
<input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b16" value="+" onClick="ajouter('+')" size="30"><br>
<input style="FONT-WEIGHT: bold; WIDTH: 140px; HEIGHT: 24px" type="reset" name="b17" value="ON/C" size="30">
<input style="FONT-WEIGHT: bold; WIDTH: 44px; HEIGHT: 24px" type="button" name="b18" value="=" onClick="calcul()" size="30"><br>
<input style="FONT-WEIGHT: bold; WIDTH: 60px; HEIGHT: 24px" type="button"  class="button" value="sqrt " onClick="fonction_speciale('sqrt')">
<input style="FONT-WEIGHT: bold; WIDTH: 60px; HEIGHT: 24px" type="button"  class="button" value=" pow " onClick="fonction_speciale('pow')">
<input style="FONT-WEIGHT: bold; WIDTH: 60px; HEIGHT: 24px" type="button"  class="button" value=" log " onClick="fonction_speciale('log')">
</center>
</form>
</th>
</table>


</body>
</html>


// PAGE 2 !

<html>

<head>
<title>Calculatrice Simple</title>
</head>

<body vlink="#0000FF">

<p><a href="calcul.htm" target="popup"
onmouseover="this.style.color='red'"
onmouseout="this.style.color='blue'"
onclick="window.open('','popup','width=218,height=215,left=100,top=100,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,status=no')">Calculatrice</a>
</p>
</body>
</html>

Conclusion

Voilà, et puis regardez le fichier zip si vous ne comprennez pas ou si ça ne marche pas
Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

25 juin 2006 12:34:38 :
Je me suis aperçu que la fonction diviser ("/") ne marchait pas ! J'ai donc corriger le problème.
  • signaler à un administrateur
    Commentaire de lgh le 26/06/2006 17:49:41

    Sympa, mais toujours les mêmes erreurs: 0,3/3 par exemple. Cela mérite un peu de finition...

  • signaler à un administrateur
    Commentaire de nexan44 le 26/06/2006 18:07:11

    Oui merci je m'en était pas aperçu, mais toujours est-il que je ne comprend pourquoi ça fait 0,999999999999999 au lieu de 0,1 ; bizare  

  • signaler à un administrateur
    Commentaire de Nono8379 le 28/06/2006 09:04:17

    je ne serai pas très surpris que tu ais en fait 0.99999 avec un point... et si tu fait 0,3/3 ce qui se passe est que tu divises en fait 3/3 tout simplement parce que la virgule n'est pas considérée comme ton séparateur entre ta partie entière et tes chiffres derrière la "virgule"...

    à tester...

  • signaler à un administrateur
    Commentaire de nexan44 le 28/06/2006 20:33:30

    oui mais le bug est pareil avec un point quil lui réprésente bien le séparateur. J'ai essayé avec d'autres chiffres, par exemple : 0,50/2, là on a le bon résultat. Donc je comprends toujours pas le problème du 0.3/3.

    note : faut avouer que pour aller taper 0.3/3 sur une calculatrice c'est qu'on est vraiment nul en math !! lol

  • signaler à un administrateur
    Commentaire de lgh le 29/06/2006 17:44:15

    Le problème existe aussi avec 12,99+11; la seule solution que j'ai trouvée est d'arrondir, mais cela ne résoud pas tous les problèmes. Qui résoudra ce casse tête ?
    LGH

  • signaler à un administrateur
    Commentaire de Nono8379 le 04/07/2006 17:01:32

    http://www.thescripts.com/forum/thread91162.html

    en gros (tres gros...) c'est lié à la représentation des chiffres dans javascript. Donc çà va être difficile d'utiliser directement la fonction eval si tu veux un résultat précis...

  • signaler à un administrateur
    Commentaire de meryem480 le 25/10/2006 19:36:53

    mon problème c'est avec 12,2,5*/25 ; ça existe pas mais il faut faire
    un contrôleur de virgule
    je veu un resultat

  • signaler à un administrateur
    Commentaire de kazma le 14/05/2008 20:21:09

    te prend pas trop la tete javascript a la réputation de ne pas être d'une précision imparable en calcule

Ajouter un commentaire

Pub



Appels d'offres

Recherche developpeur ...
Budget : 700€
SITE MARCHAND LOCATION...
Budget : 3 000€
SITE MARCHAND POUR HOTEL
Budget : 4 000€

CalendriCode

Août 2008
LMMJVSD
    123
45678910
11121314151617
18192021222324
25262728293031

VS Express FR Gratuit !

VS Express en français et 100% gratuit !

Téléchargements

Boutique

Boutique de goodies CodeS-SourceS