Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda