PHP Calculadora - PHP: Isset Isset Isset
PHP Calculadora - PHP: Isset Isset Isset
calculadora.php
<?php
if (isset($_GET['numero1']) && isset($_GET['numero2']) &&
isset($_GET['operacion'])) {
$num1 = $_GET['numero1'];
$num2 = $_GET['numero2'];
$operacion = $_GET['operacion'];
HTML
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<link rel="stylesheet" href="css/bootstrap.min.css">
<title>Calculadora</title>
<script>
function realizarOperacion() {
var numero1 =
parseFloat(document.getElementById("numero1").value);
var numero2 =
parseFloat(document.getElementById("numero2").value);
var operacion = document.getElementById("operacion").value;
if (isNaN(numero1) || isNaN(numero2)) {
alert("Ingrese números válidos.");
return;
}
<body>
<div class="container">
<div class="row">
<div class="col-md-12 bg-light rounded-5 p-5">
<h3 class="text-info p-4 text-center">Calculadora</h3>
<div class="row mt-3">
<div class="col form-group">
<label for="numero1">Ingrese el primer
número</label>
<input type="text" class="form-control mt-3"
placeholder="Primer número" name="numero1"
id="numero1">
</div>
<div class="col form-group">
<label for="numero2">Ingrese el segundo
número</label>
<input type="text" class="form-control mt-3"
placeholder="Segundo número" name="numero2"
id="numero2">
</div>
<div class="col form-group">
<label for="operacion">Ingrese la operación que
desea realizar</label>
<input type="text" class="form-control mt-3"
placeholder="Suma, Resta, Multiplicación o
División" name="operacion" id="operacion">
</div>
</div>
<button type="button" onclick="realizarOperacion()"
class="btn btn-secondary mt-5 mb-5">Realizar
Operación</button>
<div class="resultado" id="resultado">
<!-- El resultado se mostrará aquí -->
</div>
</div>
</div>
</div>
</body>
</html>
codigo feo
<?php
echo "<script>
//al hacer click en el boton resultado tomar los valores de los input y
realizar la operacion
boton.addEventListener('click', function() {
if (operacion == 'suma') {
} else {
}
//si en la division el valor2 es 0 mostrar mensaje de error
if (valor2 == 0) {
});
input[i].style.border = 'none';
input[i].style.borderBottom = '1px solid black';
input[i].style.width = '100px';
input[i].style.margin = '10px';
input[i].style.padding = '10px';
input[i].style.fontSize = '20px';
input[i].style.textAlign = 'center';
document.body.style.textAlign = 'center';
</script>";