Process form data with javascript and html

Asked

Viewed 207 times

-3

I wanted to make a program that the user would send 3 notes and after pressing "Calculate", you would be redirected to a page that would appear your average. Who could help me:

 function calcular()
        {
            var ac1 = parseInt(document.getElementById('ac1').value, 10);
            var ac2 = parseInt(document.getElementById('ac2').value, 10);
            var ac4 = parseInt(document.getElementById('ac4').value, 10);              
            var media = ((ac1*2)+(ac2*2)+ac4)/5;
            alert("Sua média desta etapa foi "+media);
        }
<html>
    <head>

        <style>
            input {
                margin-left: 100px;
                width: 45px;
            }
        </style>
    </head>
    <body>
        <form action="/teste1pag2" method="get">
                Digite sua nota da Ac1 aqui: <input type="number" id="ac1" min="0" max="10"> <br> 
                Digite sua nota da Ac2 aqui: <input type="number" id="ac2"> <br>
                Digite sua nota de participa&ccedil;&atilde;o aqui: 
                <input type="text" id="ac4" style="margin-left: 49px"> <br>
                <input type="submit" onblur="calcular()" value="Calcular!">
        </form>


    </body>
</html>
Thank you in advance!

  • 1

    https://pt.meta.stackoverflow.com/questions/5483/manual-de-como-n%C3%83o-fazer-perguntas/5485#5485

  • opa mano, I learned already rs

  • Learn more by touring the Sita https://answall.com/tour

  • When an answer solves your problem mark it as accepted. See how in https://i.stack.Imgur.com/jx7Ts.png and why in https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079

1 answer

0

Using Javascript and HTML only:

Script

 function calcular()
        {
            var ac1 = parseInt(document.getElementById('ac1').value, 10);
            var ac2 = parseInt(document.getElementById('ac2').value, 10);
            var ac4 = parseInt(document.getElementById('ac4').value, 10);              
            var media = ((ac1*2)+(ac2*2)+ac4)/5;
            alert("Sua média desta etapa foi "+media);
            
            window.location.href = "pagina-destino.html?media="+media;
        }

HTML - a tag <form>...</form> is not necessary for this solution.

Digite sua nota da Ac1 aqui: <input type="number" id="ac1" min="0" max="10"> <br> 
Digite sua nota da Ac2 aqui: <input type="number" id="ac2"> <br>
Digite sua nota de participa&ccedil;&atilde;o aqui: 
<input type="text" id="ac4" style="margin-left: 49px"> <br>
<input type="submit" onclick="calcular()" value="Calcular!">

target page.html

//Somente funciona para um parametro
//o split separa a string quando encontra o ?
var variaveis=location.search.split("?");
var quebra = variaveis[1].split("=");

//o document.whitein escreve no html o conteudo
document.writeln ("O valor da média é: " + quebra[1]);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.