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

109
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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