Error in html file

-2

I'm trying to make a form in html where it gets a person's name and gender, and make comparisons to see if the past age is greater than the age that is currently in the textbox. man), if any, will pass the age that was passed in the textbox to one of these textbox depending on the person's gender, I do not understand mt of html, javascript nor css;

Code below:

<html>
<script>
function execucoes()
{

    if(form1.nome.value == "" && form1.idade.value == "" && form1.sexo[0].checked == false && form1.sexo[1].checked == false)
    {
    {alert("Preencha todos os campos!");}
    }
    else
    {
        if(parseInt(form1.idademaisvelho.value) < parseInt(form1.idade.value) || parseInt(form1.idademaisvelha.value) < parseInt(form1.idade.value))
        {
            if(form1.sexo[0].checked == true)
            {
            form1.nomemaisvelho.value = form1.nome.value;
            form1.idademaisvelho.value = form1.idade.value;
            }
            else
            {
            form1.nomemaisvelha.value = form1.nome.value;
            form1.idademaisvelha.value = form1.idade.value;
            }   
        }
    }
}
</script>
<body>
<form name = "form1">
Digite o seu nome: <input type = text name = "nome" value = "">
<br><br>
Sexo: Masculino<input type = radio name = "sexo" value = "">
      Feminino<input type = radio name = "sexo" value = "">
<br><br>
Digite a sua idade: <input type = text name = "idade" value = "0">
                    <input type = button name = "classificar" onclick = "execucoes()" value = "Classificar">
<br><br>
Nome do Homem mais velho: <input type = text name = "nomemaisvelho" value = "" disabled>
Idade do Homem mais velho: <input type = text name = "idademaisvelho" value = "" disabled>
<br><br>
Nome da Mulher mais velha: <input type = text name = "nomemaisvelha" value = "" disabled>
Idade da Mulher mais velha: <input type = text name = "idademaisvelha" value = "" disabled>
</body>
</html>
    
asked by anonymous 25.10.2016 / 01:18

1 answer

0

You can paste this code that will work;)

<html>
<script>
function execucoes() {
    var form = document.forms[0];
    var idade = form.querySelector('input[name="idade"]');
    var nome = form.querySelector('input[name="nome"]');
    var sexo1 = form.sexo[0];
    var sexo2 = form.sexo[1];
    var nomeMaisVelho = form.querySelector('input[name="nomemaisvelho"]');
    var nomeMaisVelha = form.querySelector('input[name="nomemaisvelha"]');
    var idadeMaisVelho = form.querySelector('input[name="idademaisvelho"]');
    var idadeMaisVelha = form.querySelector('input[name="idademaisvelha"]');
    if(nome.value == "" && idade.value == "" && sexo1.checked == false && sexo2.checked == false) {
        alert("Preencha todos os campos!");
    } else if(idadeMaisVelho.value < idade.value && sexo1.checked == true || idadeMaisVelha.value < idade.value && sexo2.checked == true) {
            if(sexo1.checked == true) {
                nomeMaisVelho.value = nome.value;
                idadeMaisVelho.value = idade.value;
            }
            else {
                nomeMaisVelha.value = nome.value;
                idadeMaisVelha.value = idade.value;
            }   
        }
    }

</script>
<body>
<form name = "form1">
Digite o seu nome: <input type = text name = "nome" value = "">
<br><br>
Sexo: Masculino<input type = radio name = "sexo" value = "">
      Feminino<input type = radio name = "sexo" value = "">
<br><br>
Digite a sua idade: <input type = text name = "idade" value = "0">
                    <input type = button name = "classificar" onclick = "execucoes()" value = "Classificar">
<br><br>
Nome do Homem mais velho: <input type = text name = "nomemaisvelho" value = "" disabled>
Idade do Homem mais velho: <input type = text name = "idademaisvelho" value = "" disabled>
<br><br>
Nome da Mulher mais velha: <input type = text name = "nomemaisvelha" value = "" disabled>
Idade da Mulher mais velha: <input type = text name = "idademaisvelha" value = "" disabled>
</body>
</html>
    
25.10.2016 / 15:29