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é: 10 254 / 554

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
 

Fichier Zip

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

Historique

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.

Commentaires et avis

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

Discussions en rapport avec ce code source dans le forum

Rafraichir la fenetre "parent" [ par aurélien ] Bonjour à tous, J'ai une page en html/php a partir de laquelle, en cliquant sur un bouton, j'ouvre un popup, et j'aimerais que lorsque je ferme ce pop Fermeture de formulaire [ par Freddy ] Dans une popup,un formulaire d'ajout je voudrais qu'une fois les données envoyer,la popup se ferme automatiquementdes idées ? onUnload event, popup... [ par VicoLaChips2 ] Voila mon problème. J'ai mis dans la balise bodyd'une frame le code suivant : &lt;body onUnload="return goodbye('&lt;% =user %&gt;';"&gt;Le script : f Submit et popup [ par Woby ] Bonjour,je me demandais si il était possible d'ouvrir une autre page par l'intermédiaire d'un bouton submit sans que la page où il se trouve ne chang Fermer PopUp [ par SYL20 ] Bonjour, je ne m'y retrouve pas... pourriez-vous m'aider en m'indiquant une formule magique permettant de fermer une fenêtre popup lorsqu'on clique su pb base de donnees - popup [ par ratch ] Bonsoir à tous,J'ai un souciJ'ai une base de données qui affiche une liste de contactsavec la possiblité de cliquer sur le nom de la personne pouravoi Fonction qui permet de fermer une popup après le chargement de cette popup [ par Nabel ] Bonjour, bonjour,Voilà, j'ai fait un script ASP qui permet de créer un ficheir xls sur le serveur, or, je ne veux pas que ce ficheir reste sur le serv pb d'ouverture fermeture de popup [ par jeffb ] bonjour,j'ai ouvert une fenetre popup avec la fonction:popupHandle=open('popup.asp', 'Cobrowsing1', 'status=no, resizable=1, scrollbars=1, toolbar=0, reload et popup [ par booth ] bonjour voilà la situationj'ai un frame qu'on va appeler "haut", et une frame qu'on va appeler "bas".à partir de la frame "haut" je lancer un pop-up e Distance popup [ par Braco ] J'ai une popup placée sur l'écran. Ce que je veux, c'est récupérer la distance ( top et left ) de cette même fenêtre une fois qu'elle à été déplacée s


Nos sponsors

Sondage...

CalendriCode

Juillet 2009
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
2728293031  

Consulter la suite du CalendriCode

Téléchargements

Comparez les prix Nouvelle version

Photothèque Nouveau !



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,406 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.