1
I’m trying to manipulate dates with jQuery. The idea is this:
The user informs the Data_vencimento
and the type (in radio button
), whether the salary is weekly, fortnightly, monthly or informed.
In the input
informed, the user will enter the number of days (for example, 20 days) so that jQuery can calculate the salaries.
Example:
- User reports due date: 14/11/2018;
- User selects the weekly salary;
- jQuery calculates and fills the value of
input #dt_venc1
with the date 21/11/2018. (14 + 7).
Only that the alert(dtVenc1)
returns a NaN
.
How do you manipulate dates with jQuery? It seems that manipulating dates with PHP is much easier. But with jQuery, it would be independent of the language used.
$(document).ready( function () {
$('#data_vencimento').on('blur', function() {
alert('Usuário utilizando o input "DATA_VENCIMENTO"');
var dtVenc = new Date();
var dtVenc1 = new Date();
dtVenc = $('#data_vencimento').val();
dtVenc1 = dtVenc1.setDate(dtVenc1 + 7);
alert(dtVenc);
alert(dtVenc1);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
<div class="form-group col-md-2">
<label class="control-label" for="data_vencimento">Data Vencimento *</label>
<input type="text" class="form-control datepicker required" name="data_vencimento" id="data_vencimento">
</div>
<div class="form-group col-md-2">
<label class="control-label" for="data_prorrogacao">Data Prorrogacao</label>
<input type="text" class="form-control datepicker" name="data_prorrogacao" id="data_prorrogacao">
</div>
</div>
<div class="row">
<div class="form-check form-check-radio form-check-inline">
<label class="form-check-label" >Tipo de Parcelamento:</label>
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="SEMANAL"> Semanal
<span class="circle">
<span class="check"></span>
</span>
</label>
</div>
<div class="form-check form-check-radio form-check-inline">
<label class="form-check-label">
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio2" value="QUINZENAL" checked="checked"> Quinzenal
<span class="circle">
<span class="check"></span>
</span>
</label>
</div>
<div class="form-check form-check-radio form-check-inline">
<label class="form-check-label">
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio3" value="MENSAL" checked="checked"> Mensal
<span class="circle">
<span class="check"></span>
</span>
</label>
</div>
<div class="form-check form-check-radio form-check-inline">
<label class="form-check-label">
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio4" value="INFORMADO"> Informado
<span class="circle">
<span class="check"></span>
</span>
</label>
</div>
<div class="col-md-2">
<div class="form-group has-label">
<label class="bmd-label-floating" for="dias">Qtd. dias</label>
<input class="numero form-control" type="text" name="dias" size="03"
id="dias">
</div>
</div>
</div>
Thanks, I’ll take a look at that library.
– Ivan