Pull data from an input

Asked

Viewed 40 times

0

<html>
   <head>
   </head>
   <body>
   <input type="text" id="dias">
   <input type="date" id="ativacao">
   <input type="date" id="vencimento">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script>
         $('#ativacao')[0].valueAsDate = new Date();

$('#ativacao').change(function() {
  var date = this.valueAsDate;
  date.setDate(date.getDate() + $("#dias").val();
  $('#vencimento')[0].valueAsDate = date;
});

$('#ativacao').change();
    </script>
   </body>
   </html>``

I have this script here, there on the 14th would be the days, would have to put something there to pull the value of an input (both days?) I put corforme said below, but it ta returning random dates I’m new to jquery

1 answer

0

Hello, good afternoon!

Follow an example I did to try to help you.

$('#ativacao')[0].valueAsDate = new Date();

$('#ativacao').change(function() {
  var data = this.valueAsDate;
  
  data.setDate(parseInt(data.getDate()) + parseInt($('#dias').val()));
  
  $('#vencimento')[0].valueAsDate = data;
  
});

$("#executar").click(function(){
    $('#ativacao').change();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


   <input type="number" id="dias" placeholder="dias" />
   <input type="date" id="ativacao" />
   <input type="date" id="vencimento" />
   <input type="button" id="executar" value="Executar" />

Browser other questions tagged

You are not signed in. Login or sign up in order to post.