Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

116
Visualizações
Contact Form - JQuery Age Calculation and Field Omission

i have this idea of calculating the age from the data field of a contact form using JQuery and then use the age value to hide or show other fields of the form.

Here's a draft of the idea that i've assembled with few code snippets found on the web (sadly, i'm not used with JQuery):

<script type="text/javascript">
jQuery(document).ready(function ($) {
    function getAge("#bdate") {
        var today = new Date();
        var birthDate = new Date("#bdate");
        var age = today.getFullYear() - birthDate.getFullYear();
        var m = today.getMonth() - birthDate.getMonth();
        if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
        age--;
        }
    }
    $(document).ready(function() {
        $("#genitori").hide();
        $('#bdate').change(function() {
            function getAge(bdate) {
                var today = new Date();
                var birthDate = new Date(bdate);
                var age = today.getFullYear() - birthDate.getFullYear();
                var m = today.getMonth() - birthDate.getMonth();
                if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
                    age--;
                }
            }
            
            if (age<18) {
                $("#genitori").show();
            }
            else {
                $("#genitori").hide();
            }
        }
            
    });
        
}
</script>
<table>
    <tr>
        <td>
            <h3> User </h3>
        </td>
    </tr>
    <tr>
        <td>
            <label for="name">Name:</label>
            <input type="text*" id="name">
        </td>
        <td>
            <label for="birthday">Birthday:</label>
            <input type="date" id="bdate">
        </td>
    </tr>
 <div id="parents">
  <tr>
        <td>
            <h3> Parents </h3>
        </td>
    </tr>
    <tr>
        <td>
            <label for="Pname">Parents Name:</label>
            <input type="text*">
        </td>
    </tr>
</div>
</table>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

IMHO, you have no idea what are you doing. But first, you make a function named getAge it bracket put a variable, name it as you want i.e. birthday; this birthday put here var birthDate = new Date(birthday); and now you can use this function on your inputs value in this way. Take a value from input like var valueOfInput = $("#dbdate").val() and put this value into function function getAge (valueOfInput) this is how you have result of counting but you want use it to if statement, best you can do it is to make a variable which hold this value; so after the function execute put var resultOfFunction or whatever you want. Now is final part you have to use this variable to if statement just like if(resultOfFunction>18){return secretField.show();}else{return secretField.hide()}

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda