# .NET and More > ASP.NET And ASP.NET Core > VS 2019 java script error Unable to get property '0' of undefined or null reference

## Makumbi

Please help i wanted to use this code to validate marks enter and also to tick the value enter using java but i have not been successful please help.
i wanted upon entering a score the checkbox is ticked using this very code


```
function GetSelectedRow(UserLink) {
    var row = UserLink.parentNode.parentNode;
    var rowIndex = row.rowIndex - 1;
    var userId = row.cells[0].innerHTML;
    var lable = row.getElementsByTagName("input")[2].value;
    if (lable == null || lable == "") {
        row.getElementsByTagName("input")[8].value = "d";
        return true;
    }
    else
        row.getElementsByTagName("input")[8].value = "";

    if (lable >= 0 && lable <= 100) {
        return true;
    }
    else {
        alert("Must be between 1 and 100");
        return false;
    }
}
```

iam getting error at line 4


```
    var userId = row.cells[0].innerHTML;
```

it flags error
Unable to get property '0' of undefined or null reference



```
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Classinterview.aspx.vb" Inherits="INTERVIEWSVB.Classinterview" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>


<!DOCTYPE html>
<script src="../Scripts/Validate200.js"></script>
<script src="../Scripts/arrowkeysenable.js"></script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>


    <style type="text/css">
        .newStyle1 {
            color: #A0A0A0;
        }
        .auto-style1 {
            width: 117px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <table class="newStyle1">
            <tr>
                <td><strong>Class</strong></td>
                <td>
                    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
                        <asp:ListItem>P1</asp:ListItem>
                        <asp:ListItem>P2</asp:ListItem>
                        <asp:ListItem>P3</asp:ListItem>
                        <asp:ListItem>P4</asp:ListItem>
                        <asp:ListItem>P5</asp:ListItem>
                        <asp:ListItem>P6</asp:ListItem>
                        <asp:ListItem>P7</asp:ListItem>
                    </asp:DropDownList>
                </td>
                <td colspan="2"><strong>Stream </strong>
                    <asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True">
                        <asp:ListItem>NONE</asp:ListItem>
                        <asp:ListItem>A</asp:ListItem>
                        <asp:ListItem>B</asp:ListItem>
                        <asp:ListItem>C</asp:ListItem>
                        <asp:ListItem>D</asp:ListItem>
                        <asp:ListItem>E</asp:ListItem>
                        <asp:ListItem>F</asp:ListItem>
                        <asp:ListItem>G</asp:ListItem>
                        <asp:ListItem>H</asp:ListItem>
                        <asp:ListItem>J</asp:ListItem>
                        <asp:ListItem>K</asp:ListItem>
                    </asp:DropDownList>
                    <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
                </td>
            </tr>
            <tr>
                <td><strong>Intake </strong></td>
                <td>
                    <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="intake" DataValueField="intake">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:INTERVIEWSConnectionString %>" SelectCommand="SELECT [intake] FROM [Intakes]"></asp:SqlDataSource>
                </td>
                <td>
                    <asp:Button ID="Button1" runat="server" Text="Submit Class" />
                </td>
                <td class="auto-style1">
                    <asp:Button ID="Button2" runat="server" Text="Save Record" />
                </td>
            </tr>
        </table>
&nbsp;<div>
    <asp:GridView ID="GvStudentMarks" runat="server" AutoGenerateColumns="False" OnRowDataBound="gvStudentMarks_RowDataBound">
      <Columns>
        <asp:TemplateField>
            <HeaderTemplate>
                <asp:CheckBox ID = "chkAll" runat="server" AutoPostBack="true"  />
            </HeaderTemplate>
            <ItemTemplate>
                <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true"  />
            </ItemTemplate>
        </asp:TemplateField>

          <asp:TemplateField HeaderText="Account">
              <EditItemTemplate>
                  <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Account") %>'></asp:TextBox>
              </EditItemTemplate>
              <ItemTemplate>
                  <asp:Label ID="Label2" runat="server" Text='<%# Bind("Account") %>'></asp:Label>
              </ItemTemplate>
          </asp:TemplateField>
          <asp:TemplateField HeaderText="Name">
              <EditItemTemplate>
                  <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
              </EditItemTemplate>
              <ItemTemplate>
                  <asp:Label ID="Label3" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
              </ItemTemplate>
          </asp:TemplateField>
          <asp:TemplateField HeaderText="Category">
              <EditItemTemplate>
                  <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Category") %>'></asp:TextBox>
              </EditItemTemplate>
              <ItemTemplate>
                  <asp:Label ID="Label4" runat="server" Text='<%# Bind("Category") %>'></asp:Label>
              </ItemTemplate>
          </asp:TemplateField>
          <asp:TemplateField HeaderText="Stream">
              <EditItemTemplate>
                  <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Stream") %>'></asp:TextBox>
              </EditItemTemplate>
              <ItemTemplate>
                  <asp:Label ID="Label5" runat="server" Text='<%# Bind("Stream") %>'></asp:Label>
              </ItemTemplate>
          </asp:TemplateField>
        <asp:TemplateField HeaderText="Eng">
            <ItemTemplate>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:Label ID="lblEng" runat="server" Text='<%# Eval("Eng") %>'  Visible="False"></asp:Label>
                        <asp:TextBox ID="TxtEng" runat="server" OnTextChanged="txtEng_TextChanged" Text='<%# Eval("Eng") %>' onkeyup="enter(this)" AutoPostBack="True" Height="16px" Width="58px" onchange="return GetSelectedRow(this)" ></asp:TextBox>
                        <asp:RangeValidator ID="RangeValidator1" runat="server" BackColor="#FF99FF" ControlToValidate="TxtEng" Display="Dynamic" ErrorMessage="Invalid" MaximumValue="100" MinimumValue="0" SetFocusOnError="True" Type="Double"></asp:RangeValidator>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Maths">
            <ItemTemplate>
                <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                    <ContentTemplate>
                        <asp:Label ID="lblMaths" runat="server" Text='<%# Eval("Maths") %>' Visible="False"></asp:Label>
                        <asp:TextBox ID="TxtMaths" runat="server" OnTextChanged="txtMaths_TextChanged" Text='<%# Eval("Maths") %>' onkeyup="enter(this)" AutoPostBack="True" Width="48px" onchange="return GetSelectedRow(this)"></asp:TextBox>
                        <asp:RangeValidator ID="RangeValidator2" runat="server" BackColor="#FF99FF" ControlToValidate="TxtMaths" Display="Dynamic" ErrorMessage="Invalid" MaximumValue="100" MinimumValue="0" SetFocusOnError="True" Type="Double"></asp:RangeValidator>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="TotalMarks">
            <ItemTemplate>
                <asp:Label ID="lblTotalMarks" runat="server" Text='<%# Eval("avgs") %>' Visible="False"></asp:Label>
                <asp:TextBox ID="txtTotalmarks" runat="server" Text='<%# Eval("Avgs") %>'></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Average">
            <ItemTemplate>
                <asp:TextBox ID="txtAverage" runat="server" Text='<%# Eval("Avgs2") %>'></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>

        <asp:BoundField HeaderText="Sst" DataField="Sst" />
        <asp:BoundField DataField="Science" HeaderText="Science" />
        <asp:TemplateField HeaderText="Entered Date">
            <EditItemTemplate>
                <asp:TextBox ID="Entrydate" runat="server" Text='<%# Bind("emarksdate") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("emarksdate") %>'></asp:Label>
                <asp:TextBox ID="Entrydates" runat="server" Text='<%# Eval("emarksdate") %>'></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
                        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="False">
                        </asp:ScriptManager>
        </div>
    </form>
</body>
</html>
```

----------


## NeedSomeAnswers

```
 var userId = row.cells[0].innerHTML;
```




> it flags error
> Unable to get property '0' of undefined or null reference


Either row is undefined or cells[0] is undefined. 



```
var row = UserLink.parentNode.parentNode;
```

alert out row after this line to check if it's undefined. 

alert(row);

Its likely your getting the row incorrectly with the UserLink.parentNode.ParentNode syntax but check with that alert and post back !

----------

