I try to insert date from one column into date field of class .choice but can't do this. When I return date field length then it shows 10 signs so it's ok. Date field also allows 10 signs to be input.
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime? PaymentDate { get; set; }
View:
<tr>
<td class="payment">
@Html.DisplayFor(modelItem => item.PaymentDate)
</td>
<td>
<select id="decisionList">
<option value="0" selected></option>
<option value="1">None</option>
</select>
</td>
<td class="choice"></td>
</tr>
JS:
document.querySelectorAll("#decisionList").forEach(elem => elem.addEventListener("change", function () {
var selectedOptionIndex = this.options[this.selectedIndex].index;
var invoiceDateText = this.closest('tr').querySelector('.payment').textContent.trim();
var finalChoice = this.closest('tr').querySelector('.choice');
alert(invoiceDateText.length); //returns 10 signs so it's ok
switch (selectedOptionIndex) {
case 0:
finalChoice.innerHTML = '<input type="date">'
break;
case 1:
finalChoice.innerHTML = '<input type="date" value="' + invoiceDateText + '">' // and here doesn't show the date from invoiceDateText
break;
default:
finalChoice.innerHTML = ''
}}));