Generate date sequence within input automatically

0

How can I generate a date sequence and place each date within inputs (OS INPUTS ALREADY EXIST WITHIN A FORM) from the start date and end date automatically?

I put the start and end date, and script generates the date range on inputs that already exist. It is not possible to generate the input's. And yes put the dates generated within them. A input for each date.

SCRIPT TEST GENERATING DATE INTERVAL

 var dt= new Date();
 var ndt = new Date(1850,01,27);      
 var diassem = ndt.getDay();     
 var mes=ndt.getMonth();

 var meses = new Array("Janeiro","Fevereiro","março");
 var dias = new Array("Domingo","Segunda","Terça","Quarta","Quinta","Sexta","Sabado");
    for (var i = 0; i <= 10; i++) 
    {      
      var dia=ndt.getDate()+i;
      document.write(dia+"________");
      *****AQUI EU CONSIGO IMPRIMIR, MAS N CONSIGO PEGAR CADA DATA GERADA E COLOCAR NOS INPUTS DE ACORDO COM O ID DE CADA UM ( dti0, dti1, dti2....)****

    };

TEST FORM WHERE I WILL SEND SAVE NO DATABASE

<form method="POST" action="teste.php">
 <input type="text"  name="dti0" id="dti0" autocomplete="off"/><br>
 <input type="text"  name="dti1" id="dti1" autocomplete="off"/><br>
 <input type="text"  name="dti2" id="dti2" autocomplete="off"/><br>
 <input type="text"  name="dti3" id="dti3" autocomplete="off"/><br>   
</form>

I kind of sketch my code. In it I can generate the sequence of dates, but I still do not know how to put each date within a input

    
asked by anonymous 02.01.2019 / 14:20

1 answer

0

The method toLocaleDateString () returns a string with the representation of part of the date based on the language.

var start = new Date("1850,01,27");

var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };

document.getElementById("dti0").value =start.toLocaleDateString('pt-BR',options);

for (var i = 1; i <= 10; i++) 
{
   //estabelece um intervalo entre as datas    
   var newDate = start.setDate(start.getDate() + 3);
   start = new Date(newDate);
   //coloca as datas nos inputs
   document.getElementById("dti"+i).value =start.toLocaleDateString('pt-BR', options);
}
<input type="text"  name="dti0" id="dti0" autocomplete="off" size="51"/><br>
<input type="text"  name="dti1" id="dti1" autocomplete="off" size="51"/><br>
<input type="text"  name="dti2" id="dti2" autocomplete="off" size="51"/><br>
<input type="text"  name="dti3" id="dti3" autocomplete="off" size="51"/><br>
<input type="text"  name="dti3" id="dti4" autocomplete="off" size="51"/><br>
<input type="text"  name="dti3" id="dti5" autocomplete="off" size="51"/><br>
<input type="text"  name="dti3" id="dti6" autocomplete="off" size="51"/><br>
<input type="text"  name="dti3" id="dti7" autocomplete="off" size="51"/><br>
<input type="text"  name="dti3" id="dti8" autocomplete="off" size="51"/><br>
<input type="text"  name="dti3" id="dti9" autocomplete="off" size="51"/><br>
<input type="text"  name="dti3" id="dti10" autocomplete="off" size="51"/><br>
    
04.01.2019 / 00:44