I need to get addicted, one field from another.
selectbox has a list of options
If the first or e.g. 5 option is selected in the dropdownbox, class:selectboxlist
then I would like set value '-1' in the second column class:days_tpu
What I was able to do is at the bottom of the post
View:
<table>
<tr>
<td id="td01" class="@userColor1">@Html.DropDownListFor(m => m.Model1[nr_rows].PrzyczynaNieobecnosci, new SelectList(Enum.GetValues(typeof(Urlopy))), " ", new { @class = "selectboxlist" })</td>
<td id="td01">@Html.TextBoxFor(m => m.Model1[nr_rows].DniOdpracowania, new { @class = "days_tpu", @readonly = true })</td>
</tr>
</table>
Convert to normal html:
<select class="selectboxlist" id="Model1_0__PrzyczynaNieobecnosci" name="Model1[0].PrzyczynaNieobecnosci"><option value=""> </option>
<option>dzwol</option>
<option>szkol</option>
<option>chor</option>
<option>opie</option>
<option>odziec</option>
<option>nn</option>
<option>psz</option>
<option>uż</option>
<option>chopie</option>
</select>
<input class="days_tpu" id="Model1_0__DniOdpracowania" name="Model1[0].DniOdpracowania" readonly="True" type="text" value="0">
Model:
public Urlopy? PrzyczynaNieobecnosci { get; set; }
public enum Urlopy
{
dzwol = 1,
szkol = 2,
chor = 3,
opie = 4,
odziec = 5,
chopie = 16
}
What I have tried:
I tried: (but it doesn't work at all)
const table = document.querySelector('table');
table.addEventListener('change', function (e) {
const classList = e.target.classList;
if (classList.contains('selectboxlist') ) {
const tr = e.target.parentNode.parentNode;
const [selectboxlist, days_tpu] = [...tr.querySelectorAll('.selectboxlist,.days_tpu')];
if(selectboxlist.value == 1) {
days_tpu.value = 1
}
if(selectboxlist.value == dzwol ) {
days_tpu.value = 1
}
}
});