Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
Mostrar la fecha actual en un cuadro de texto después de hacer clic en una casilla de verificación

Estoy creando un formulario para estandarizar los nombres de archivo (soy editor de video). Después de mucha investigación, copiando, pegando y probando, ya casi llego. Solo necesito mostrar la fecha actual al final del nombre del archivo después de que el usuario haga clic en la casilla de verificación correspondiente.

El HTML tiene el código para obtener la fecha actual y formatearla como quiero (AAMMDD), pero por mi vida no puedo encontrar una manera de mostrarla al final del nombre del archivo . El código para mostrar la fecha funciona porque puedo habilitar/deshabilitar el texto, pero no puedo mostrar el resultado de la función de fecha de hoy.

Este es el código para obtener la fecha actual y formatearla en AAMMDD:

 function SetDate() { var date = new Date(); var day = date.getDate(); var month = date.getMonth() + 1; var year = date.getFullYear() - 2000; if (month < 10) month = "0" + month; if (day < 10) day = "0" + day; var today = year + month + day; document.getElementById('today').value = today; }

Este es el código que agrega o elimina la fecha al final del nombre del archivo cuando hace clic en la casilla de verificación.

 function todaysdate() { var checkbox = document.getElementById('todayis'); if (checkbox.checked != false) document.getElementById('todayis').value = "DATE"; if (checkbox.checked != true) document.getElementById('todayis').value = ""; }

Este es el código de la casilla de verificación:

 Add date (YYMMDD): <input type="checkbox" onclick="todaysdate()" id="todayis" value="" />

Gracias de antemano por tu ayuda.

Editar: Agregué el código.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

También puede usar la función php Tiempo:

Establecer la zona horaria:

 date_default_timezone_set('America/New_York');

Y obtener la fecha real:

 $date_now = date('Y/m/d', time());

Entonces, para establecer el valor en la entrada:

 <input type="checkbox" value="<?php echo $date_now ?>" />
about 4 years ago · Juan Pablo Isaza Report

0

function getYYMMDDDate(date) { var year = String(date.getFullYear()).substring(2,4); var month = String(date.getMonth() + 1).padStart(2, "0"); var day = String(date.getDate()).padStart(2,"0"); return year + month + day; } ... // change this document.getElementById('todayis').value = "DATE"; document.getElementById('todayis').value = getYYMMDDDate(new Date());
about 4 years ago · Juan Pablo Isaza Report

0

En su todaysdate de fecha de hoy, establece el valor de la todayis de hoy en DATE , donde debería establecerlo en el valor de su cálculo de fecha. ¡Aquí hay un pequeño cambio en lo que tienes que probablemente debería funcionar!

 function todaysdate() { var checkbox = document.getElementById('todayis'); if (checkbox.checked != false) document.getElementById('todayis').value = getDate(); else if (checkbox.checked != true) document.getElementById('todayis').value = ""; } function getDate() { var date = new Date(); var day = date.getDate(); var month = date.getMonth() + 1; var year = date.getFullYear() - 2000; if (month < 10) month = "0" + month; if (day < 10) day = "0" + day; var today = year + "" + month + "" + day; return today; }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!