I have these variables :
« PST_INFINCDEM » is select group = (indicent=0/ demande=1) « PST_INFBLOQ » is a checkbox = (O / N) « DT_READEM » with type date.
I want to calculate the « DT_READEM » deppending on three conditions: 1- if PST_INFINCDEM = demande then DT_READEM =CURRENT Date +10 days 2- if PST_INFINCDEM = incident AND PST_INFBLOQ =O THEN DT_READEM =CURRENT Date + 2 Days 3- if PST_INFINCDEM = incident AND PST_INFBLOQ =N THEN DT_READEM =current Date + 5 days
$(document).ready(function() {
$('select').change(function(){
var item=$('select').val();
var checkedItem = $("#PST_INFBLOQ").is(":checked");
switch (item){
case "1":
var newdate = new Date();
newdate.setDate(newdate.getDate() + 10);
var dd = newdate.getDate();
var mm = newdate.getMonth() + 1;
var y = newdate.getFullYear();
if(mm<10) mm='0'+mm;
var someFormattedDate = dd + '/' + mm + '/' + y;
//document.getElementById('DT_READEM').value = someFormattedDate;
$('#DT_READEM').val(someFormattedDate);
break;
case "0":
$('#checkedItem ').click(function (event) {
if (checkedItem === false)
{
var newdate_5 = new Date();
newdate_5.setDate(newdate.getDate() + 5);
var dd = newdate_5.getDate();
var mm = newdate_5.getMonth() + 1;
var y = newdate_5.getFullYear();
if(mm<10) mm='0'+mm;
var someFormattedDate = dd + '/' + mm + '/' + y;
//document.getElementById('DT_READEM').value = someFormattedDate;
$('#DT_READEM').val(someFormattedDate);
}
else if (checkedItem === true)
{
var newdate_2 = new Date();
newdate_2.setDate(newdate_2.getDate() + 2);
var dd = newdate_2.getDate();
var mm = newdate_2.getMonth() + 1;
var y = newdate_2.getFullYear();
if(mm<10) mm='0'+mm;
var someFormattedDate = dd + '/' + mm + '/' + y;
//document.getElementById('DT_READEM').value = someFormattedDate;
$('#DT_READEM').val(someFormattedDate);
}
})
break;
default:
$('#DT_READEM').val(new Date().toLocaleDateString()).attr('disabled','disabled');
}
})
})
Resources
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<div>
<span> date </span>
<input type="date" id="DT_READEM">
</div>
<div>
<span> bloc </span>
<input type="checkbox" id="PST_INFBLOQ ">
</div>
<div>
<span> info </span>
<select id="pet-select" id="PST_INFINCDEM ">
<option value=1>demande</option>
<option value=0>indicent</option>
</select>
</div>
The problem that the result that want is true just when i select "demande" if i select "indicent" nothing is change and the checkbox is not taken into considaration even I put a condition about it
Aucun commentaire:
Enregistrer un commentaire