Click here to Skip to main content
14,454,989 members
Rate this:
Please Sign up or sign in to vote.
I have c # code in view: (It create time inputs for me with the class described)

<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:

table.addEventListener('change', function (e) {
    const classList =;
    if (classList.contains('start') || classList.contains('end') || classList.contains('gethours')) {
        //retrieve the associated inputs
        const tr =;
        const [additional_free, overtime] = ['.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?
Updated 9-Feb-20 2:14am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100