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

151
Vistas
Cómo agregar la función de fecha

Quiero agregar (mostrar también) 21 días a la fecha de la primera dosis si se seleccionó BioNTech o agregar 28 días a los días seleccionados si se seleccionó Sinovac.

 Enter your First name: <br> <input font-size="30px" style="padding:10px; width:500px;font-size:20px"type="text" name="FName" placeholder="Last Name"> <br> <br /> Enter your Last name: <br /> <input font-size="30px" style="padding:10px; width:500px;font-size:20px" type="text" name="LName" placeholder="First Name"> <br> <br /> Enter your Contact number: <br> <input font-size="30px" style="padding:10px; width:500px;font-size:20px" type="text" name="ContactN" placeholder="Contact"> <br> <br /> Enter the date of First Shot: <br> <input font-size="30px" style="padding:10px; width:500px; font-size:20px" type="date" name="DateR" value="dd/mm/yy"> <br> <br /> Type of 1st Shot: <p style="color: #C5C6C7"> <input style="font-size:20px" type="radio" name="Fshot" value="BionTech" checked> BioNTech &nbsp &nbsp <input style="font-size:20px" type="radio" name="Fshot" value="SinoVac"> SinoVac </p> </div> </center> <br /><br> <input type="submit" style="font-size:22px" value="Book Now" class="hero-btn">
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

El siguiente fragmento debería hacer el trabajo:

 const d=document.querySelector("[name=DateR]"), d2=document.querySelector("[name=DateS]"), t=[...document.querySelectorAll("[name=Fshot]")]; d.addEventListener("change",addDate); t.forEach(e=>e.onclick=addDate); function addDate(){ if(!d.value) return; // exit quietly if no date has yet been selected const dat=new Date(d.value); dat.setDate(dat.getDate()+ (t.find(e=>e.checked).value==="BionTech" ? 21 : 28)); d2.value=dat.toISOString().slice(0,10); }
 <div> Enter your First name: <br> <input font-size="30px" style="padding:10px; width:500px;font-size:20px"type="text" name="FName" placeholder="First Name"> <br> <br /> Enter your Last name: <br /> <input font-size="30px" style="padding:10px; width:500px;font-size:20px" type="text" name="LName" placeholder="Last Name"> <br> <br /> Enter your Contact number: <br> <input font-size="30px" style="padding:10px; width:500px;font-size:20px" type="text" name="ContactN" placeholder="Contact"> <br> <br /> Enter the date of First Shot: <br> <input font-size="30px" style="padding:10px; width:500px; font-size:20px" type="date" name="DateR" value="dd/mm/yy"> <br> <br /> Type of 1st Shot: <p style="color: #C5C6C7"> <input style="font-size:20px" type="radio" name="Fshot" value="BionTech" checked> BioNTech &nbsp &nbsp <input style="font-size:20px" type="radio" name="Fshot" value="SinoVac"> SinoVac </p> <input font-size="30px" style="padding:10px; width:500px; font-size:20px" type="date" name="DateS" readonly> </div> </center> <br /><br> <input type="submit" style="font-size:22px" value="Book Now" class="hero-btn"> </div>

La función universal de manejo de eventos addDate() hace todo el trabajo pesado:

  • recopila la fecha de la primera vacunación y crea un objeto dat () a partir de ella
  • identifica en qué botón de radio se hizo clic y luego agrega 21 o 28 días al objeto Fecha dat
  • luego asigna el valor en cadena de dat al segundo campo de entrada de fecha (solo lectura).

El objeto Date de JavaScript permite agregar una fecha simple cambiando la parte del "día del mes" con .setDate() . El objeto Date convierte los números de fecha "no válidos" en fechas válidas cambiando al mes siguiente si es necesario.

about 4 years ago · Santiago Trujillo 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