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

110
Vistas
Display the current date in a text box after clicking a checkbox

I'm building a form to standardize filenames (I'm a video editor). After a lot of research, copying, pasting and testing I'm almost there. I just need to display the current date at the end of the filename after the user clicks on the corresponding checkbox.

The HTML has the code to get the current date and to format it as I want (YYMMDD), but for the life of me I can't find a way to display it at the end of the filename. The code to display the date works because I can enable/disable text, but I can't display the result of the todaysdate function.

This is the code to get the current date and format it to YYMMDD:

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;
}

This is the code that adds or removes the date at the end of the filename when you click the checkbox.

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

This is the code for the checkbox:

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

Thanks in advance for your help.

Edit: Added the code.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You can also use the php function Time:

Set the timezone:

date_default_timezone_set('America/New_York');

And get the actual date:

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

So, to set the value on the input:

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

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 Denunciar

0

In your todaysdate function you set the value of the todayis input to DATE, where you should be setting it to the value of your date calculation. Here’s just a little change to what you have that should probably work!

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 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