Page 1 sur 1

affiche l'écran d'une calculatrice

Posté : 26 mars 2015, 15:18
par passnic
Bonjour, je viens de commencer le php et j'aimerai réaliser une calculatrice basique. je suis bloqué au niveau de l'affichage de l'expression arithmétique de saisie du clavier. je voudrai afficher toutes les saisies du clavier avant d’évaluer l'expression
voici mon code:
<!doctype html>
<html lang="fr">
	<head>
		<title>Calculatrice</title>
		<meta charset="utf-8">
		<style>
         table { border-collapse:collapse; }
         table,td { border:1px solid black; font-family:monospace;}
         td { padding:15px; }
         a { text-decoration:none; }
		</style> 
     
    </head>
    <body>
		<h2>Calculatrice</h2>
		<table>
			<tr>
       		  	<td><a href="calculatrice.php?fonction=e">E</a></td>
                <td><a href="calculatrice.php?fonction=c">C</a></td>
                <td><a href="calculatrice.php?touche=%28">(</a></td>
				<td><a href="calculatrice.php?touche=%29">)</a></td>
			</tr>
			<tr>
				<td><a href="calculatrice.php?touche=7">7</a></td>
				<td><a href="calculatrice.php?touche=8">8</a></td>
                <td><a href="calculatrice.php?touche=9">9</a></td>
                <td><a href="calculatrice.php?touche=%2B">+</a></td>
			</tr>
            <tr>
				<td><a href="calculatrice.php?touche=4">4</a></td>
				<td><a href="calculatrice.php?touche=5">5</a></td>
                <td><a href="calculatrice.php?touche=6">6</a></td>
                <td><a href="calculatrice.php?touche=-">-</a></td>
			</tr>
            <tr>
				<td><a href="calculatrice.php?touche=1">1</a></td>
				<td><a href="calculatrice.php?touche=2">2</a></td>
                <td><a href="calculatrice.php?touche=3">3</a></td>
                <td><a href="calculatrice.php?touche=%2A">*</a></td>
			</tr>
            <tr>
				<td><a href="calculatrice.php?touche=0">0</a></td>
				<td><a href="calculatrice.php?touche=%2C">,</a></td>
                <td><a href="calculatrice.php?touche=%3D">=</a></td>
                <td><a href="calculatrice.php?touche=%2F">/</a></td>
			</tr>
            
		</table>
			<p><b>Expression:</b> <?php 
									$expression='';
									if (isset($_GET['touche']))
									{$expression.=$_GET['touche'] ;
									
									}echo $expression;
								   ?> 
			<p><b>Résultat:</b>								</p>
    </body>
</html>

Re: affiche l'écran d'une calculatrice

Posté : 26 mars 2015, 23:57
par moogli
salut,

je pense que ta solution se trouve du coté de javascript.
les clics actionnent une fonction javascript, qui te permet d'afficher la saisie (par exemple dans un champs read only).
lorsque tu cliques sur le bouton pour valider c'est ceci que tu utilise pour le calcul.

@+

Re: affiche l'écran d'une calculatrice

Posté : 27 mars 2015, 10:13
par passnic
merci j'ai résolu le problème!