Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html lang = "es">
<head>
    <meta charset = "utf-8" />
    <title>Marina</title>
</head>
<body>
    <form id = "miForm">
        <p>
            <label for = "a">Primer valor:</label>
            <input type = "text" id = "a" />
        </p>
        
        <p>
            <label for = "b">Segundo valor:</label>
            <input type = "text" id = "b" />
        </p>
        
        <p>
            <label>Elija una opción:</label>
            <input type = "radio" name = "opcion" value = "sumar" checked /> Sumar
            <input type = "radio" name = "opcion" value = "restar" /> Restar
        </p>
        
        <input type = "submit" value = "Ejecutar" />
    </form>
</body>
</html>
 
var inputA = document.querySelector("#a"),
    inputB = document.querySelector("#b"),
    form = document.querySelector("#miForm"), a, b, opcion;
 
form.addEventListener("submit", function(event){
    event.preventDefault();
    
    a = inputA.value;
    b = inputB.value;
    opcion = document.querySelector("[name=opcion]:checked").value;
    
    if ((isNaN(a) || !isFinite(a)) || (isNaN(b) || !isFinite(b))){
        alert("Debe de ingresar valores numéricos");
    }
    else{
        a = parseInt(a);
        b = parseInt(b);
 
        if (opcion == "sumar"){
            alert(a + " más " + b + " es igual a " + (a + b));
        }else{
            alert(a + " menos " + b + " es igual a " + (a - b));
        }
    }
}, false);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
Alexis88pro
0viewers