Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have c # code in asp.net view: (It create time inputs for me with the class described)


View:
<td id="td01">@Html.TextBoxFor(m => m.Model1[nr_rows].Rozpoczecie, new { @class = "start", @type = "time" })</td>
<td id="td01">@Html.TextBoxFor(m => m.Model1[nr_rows].Zakonczenie, new { @class = "end", @type = "time" })</td>
<td id="td01">@Html.TextBoxFor(m => m.Model1[nr_rows].OdbiorGodzin, new { @class = "gethours", @type = "time" })</td>


<td id="td01">@Html.TextBoxFor(m => m.Model1[nr_rows].DniOdpracowania, new { @class = "additional_free",@type = "time", @readonly = true })</td>
<td id="td01">@Html.TextBoxFor(m => m.Model1[nr_rows].SaldoNadgodzin, new { @class = "overtime", @type = "time", @readonly = true })</td>



And I have a code that does various calculations for me:


JavaScript
table.addEventListener('change', function (e) {
    const classList = e.target.classList;
    if (classList.contains('start') || classList.contains('end') || classList.contains('gethours')) {
        //retrieve the associated inputs
        const tr = e.target.parentNode.parentNode;
        const [additional_free, overtime] = [...tr.querySelectorAll('.additional_free,.overtime')];

        additional_free.value = overtime.value     <<<<<<<<<< this


    }
});



Although everything works, I get such an unknown for me error:


> VM49:85 Uncaught TypeError: Cannot read property 'value' of undefined
at HTMLTableElement.<anonymous> (<anonymous>:85:42)


I will add that the data at the beginning are read from the database and set as the initial values ​​in this table

What I have tried:

Anybody knows what's going on?
Posted
Updated 9-Feb-20 1:14am

1 solution

JavaScript
additional_free.value = overtime.value     <<<<<<<<<< this

Probably means that one or both of the variables additional_free and overtime have not been initialised. Use your debugger to see what actual results are returned by the call to querySelectorAll. It is always a good idea to check the results of functions before using the objects; do not assume that such calls will always succeed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900