Print result of a script in an input

0

I want to convert the first text box to uppercase and lowercase, according to my function, but I do not know how to have the result printed in the text box below. Every time I click on the button, the page is reloaded and the text in the box is deleted.

function mayus() {
    var resultado
    var inicio
    var inicio = document.getElementById('original');
    var resultado = inicio.toUpperCase();
    document.getElementById('resultado'.innerHTML = resultado)
};
<!DOCTYPE html>
<html lang="es">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script type="text/javascript" src="/js/script.js"></script>
</head>

<body>
    <noscript>
        <p>
            Bienvenido
        </p>
        <p>
            La página que estás viendo requiere para su funcionamiento el uso de JavaScript. Si lo has deshabilitado intencionadamente,
            por favor vuelve a activarlo.
        </p>
    </noscript>
    <form name="formulario" id="inicial">
        <input type="text" id="original"/><br>
        <input type="text" id="resultado" /><br>
        <input type="submit" value="MAYUSCULA" onclick="mayus()" ><br>
        <input type="submit" value="minuscula">
    </form> 
</body>

</html>

    
asked by Ricardo Jesus Jarquin Perez 31.03.2017 в 16:53
source

1 answer

2

Reviewing I identify you that:

1) It does not do anything because variable inicio was not saving the value (value) of the text box

2) In my particular I assign the direct value to the HTML element I do not use append

function mayus() {
    var resultado
    var inicio
    var inicio = document.getElementById('original').value;
    var resultado = inicio.toUpperCase();
    document.getElementById('resultado').value= resultado;
};

3) submit must be buttons

<input type="button" value="MAYUSCULA" onclick="mayus()" ><br>

4) In case you want it;

function minus() {
    var resultado
    var inicio
    var inicio = document.getElementById('original').value;
    var resultado = inicio.toLowerCase();
    document.getElementById('resultado').value= resultado;
};

<input type="button" value="minuscula" onclick="minus()">
    
answered by 31.03.2017 / 16:54
source