Show only one option

1

First I enter two values, then I must show the missing value on another screen. How can I make it so that it only shows me a result?

<!DOCTYPE html>
<html>
<head>
    <!--sen-->
    <title>formulario2.2</title>
</head>
<body background="https://i.pinimg.com/originals/65/c3/fa/65c3fa41b8f7339d4f47d30e82dc32d0.gif">
    <?php   
     $senn = $_POST['senn'];
     $co = $_POST['co'];
     $hip = $_POST['hip'];

     $resultado_sen = $co / $hip;        
      echo "<br>" . "<fieldset>" . "<h2>" . "<code>" . "<center>" . "El seno mide: " . $resultado_sen . "</center>" . "</code>" . "</h2>"."<br>" . "<br>" . "</fieldset>";

     $resultado_co = $hip * $senn;
      echo "<br>" . "<fieldset>" . "<h2>" . "<code>" . "<center>" . "El cateto opuesto mide: " . $resultado_co . "</center>" . "</code>" . "</h2>"."<br>" . "<br>" . "</fieldset>";

     $resultado_hip = $co / $senn;
      echo "<br>" . "<fieldset>" . "<h2>" . "<code>" . "<center>" . "El cateto opuesto mide: " . $resultado_hip . "</center>" . "</code>" . "</h2>"."<br>" . "<br>" . "</fieldset>";    
    ?>
    </body>
</html>

This is the javascript code

function sen(){
    window.location.href="index2.2.html"; 
    var co = document.getElementById('co').value; 
    var hip = document.getElementById('hip').value;
    var senn = document.getElementById('senn').value;

    if (co== "" || hip== "" || senn== "") {
        alert ("achu, los datos son obligatorios achu!");
        return false;
    }
}

this is what html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<script type="text/javascript" src="funciones4.js"></script>
<link rel="stylesheet" type="text/css" href="estilo4.css">
<title>Practica 2.4</title>
</head>
<body bgcolor="transparent">
<div class="index2.2">
    <marquee>ENCONTRAR SEN</marquee>
    <form name="formulario2.2" action="formulario2.2.php" method="POST" id="formulario2.2">
        <center>
            <fieldset>
                <label>Sen</label>
                <input placeholder="Escribe algo porfa" type="number" name="senn" id="senn"><br><br>
                <label>Cateto opuesto</label>
                <input placeholder="Escribe algo porfa" type="number" id="co" name="co" ><br><br>
                <label>Hipotenusa</label>
                <input placeholder="Escribe algo porfa" type="number" id="hip" name="hip"><br><br>
                <button style="width:50%" id="seno" onclick="sen()">MOSTRAR</button>

            </fieldset>
        </center>

    </form>
</div>

    
asked by ally_ pretty 26.04.2018 в 06:40
source

1 answer

0

You could run it in php with the following ifs:

if($senn === NULL) {$resultado_sen = $co / $hip;}
    if($co === NULL) {$resultado_co = $hip * $senn;}
    if($hip === NULL) {$resultado_hip = $co / $senn;}

Or if you prefer to create a function in javascript when you press the button in the same way that you verify that the data is necessary but changing the "" by null

<button onclick="comprobarNulos()">TuBoton</button>

And in javascript

function comprobarNulos {
if(sen==null){
sen = co / hip;
}
if(co==null){
sen = hip * sen;
}
if(hip==null){
sen = co / sen;
}
}
    
answered by 26.04.2018 в 09:28