Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Ma super calculatrice</title>
- <style>
- body
- {
- background-color: black;
- }
- #calculatrice
- {
- border: 2px solid black;
- border-radius: 15px;
- margin-left: auto;
- margin-right: auto;
- width: 400px;
- height: 600px;
- background-color: white;
- margin-top: 50px;
- padding: 10px;
- }
- #calculatrice form
- {
- font-size: 30px;
- font-weight: bold;
- margin-top: 20px;
- }
- #calculatrice input
- {
- width: 36%;
- height: 50px;
- margin-left: 10px;
- font-size: 30px;
- font-weight: bold;
- border: 2px solid black;
- text-align: center;
- }
- #calculatrice .input_operateur
- {
- width: 50px;
- }
- #calculatrice #btn_valider
- {
- position: absolute;
- margin-left: -85px;
- margin-top: 470px;
- width: 60px;
- cursor: pointer;
- }
- #calculatrice #btn_valider:hover
- {
- color: red;
- }
- #calculatrice .btn_calculatrice
- {
- width: 50px;
- height: 50px;
- border: 2px solid black;
- float: left;
- margin-left: 35px;
- margin-top: 20px;
- text-align: center;
- font-size: 40px;
- cursor: pointer;
- }
- #calculatrice .btn_calculatrice:hover
- {
- color: white;
- background-color: black;
- }
- #calculatrice .btn_calculatrice:active
- {
- color: red;
- }
- #content
- {
- margin-top: 50px;
- }
- #result
- {
- margin-left: 3%;
- width: 92%;
- text-align: center;
- font-size: 40px;
- border: 2px solid black;
- height: 50px;
- }
- </style>
- </head>
- <body>
- <div id='calculatrice'>
- <div id='result'>
- <?php
- function operation($a, $b, $operateur)
- {
- if($operateur == "%2B")
- {
- return $a + $b;
- }
- elseif($operateur == "-")
- {
- return $a - $b;
- }
- elseif($operateur == "x" )
- {
- return $a * $b;
- }
- elseif($operateur == "%2F" || $operateur == "%25")
- {
- if($b != 0)
- {
- return $a / $b;
- }
- else
- {
- return "erreur";
- }
- }
- else
- {
- return "opérateur indéfinie";
- }
- }
- if(isset($_GET['submit']))
- {
- if(isset($_GET['nombre1']) && isset($_GET['nombre2']) && isset($_GET['operateur']))
- {
- $nombre1 = $_GET['nombre1'];
- $nombre2 = $_GET['nombre2'];
- $operateur = $_GET['operateur'];
- $result = $_GET['result'];
- $result = operation($nombre1, $nombre2, $operateur);
- echo $result;
- }
- }
- ?>
- </div>
- <form method="get" action="#">
- <input class='input_number' name='number1' id='number1'/>
- <input class='input_operateur' name='operateur' id='operateur'/>
- <input class='input_number'name='number2' id='number2'/>
- <input id='btn_valider' type='submit' value='='></input>
- </form>
- <div id='content'>
- <div class='btn_calculatrice' onclick='remplirNumber(7)'>7</div>
- <div class='btn_calculatrice' onclick='remplirNumber(8)'>8</div>
- <div class='btn_calculatrice' onclick='remplirNumber(9)'>9</div>
- <div class='btn_calculatrice' onclick='remplirNumber("+")'>+</div>
- <div class='btn_calculatrice' onclick='remplirNumber(4)'>4</div>
- <div class='btn_calculatrice' onclick='remplirNumber(5)'>5</div>
- <div class='btn_calculatrice' onclick='remplirNumber(6)'>6</div>
- <div class='btn_calculatrice' onclick='remplirNumber("-")'>-</div>
- <div class='btn_calculatrice' onclick='remplirNumber(1)'>1</div>
- <div class='btn_calculatrice' onclick='remplirNumber(2)'>2</div>
- <div class='btn_calculatrice' onclick='remplirNumber(3)'>3</div>
- <div class='btn_calculatrice' onclick='remplirNumber("x")'>x</div>
- <div class='btn_calculatrice' onclick='remplirNumber(0)'>0</div>
- <div class='btn_calculatrice' onclick='remplirNumber(",")'>,</div>
- <div class='btn_calculatrice' onclick='remplirNumber("%")'>%</div>
- <div class='btn_calculatrice' onclick='remplirNumber("/")'>/</div>
- </div>
- </div>
- </body>
- <script>
- function remplirNumber(n)
- {
- var champ1 = document.getElementById("number1");
- var champ2 = document.getElementById("number2");
- var operateur = document.getElementById("operateur");
- if(typeof n == "number" || n == ',')
- {
- if(operateur.value.length == 0)
- champ1.value += n;
- else
- champ2.value += n;
- }
- else
- operateur.value = n;
- }
- </script>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment