Error encountered when clicking on a checkbox in Bootstrap: Uncaught TypeError - Unable to access property 'click' of undefined

I'm facing an issue with a simple mvc table in my cshtml page. I am attempting to add a checkbox in one of the columns, but when I click on the checkbox, I receive the following error:

Uncaught TypeError: Cannot read property 'click' of undefined

This error seems to be originating from the bootstrap.js file:

 b.prototype.click = function(b) {
        var c = a(b.currentTarget).closest("tr").find(this.options.target)[0];
        if (a(b.target)[0] !== c)
            if (b.preventDefault(),
            c.click)
                c.click();
            else if (document.createEvent) {
                var d = document.createEvent("MouseEvents");
                d.initMouseEvent("click", !0, !0, window, 0, 0, 0, 0, 0, !1, !1, !1, !1, 0, null),
                c.dispatchEvent(d)
            }
    }

The error is triggered because the value of "c" is undefined. Oddly enough, commenting out the bootstrap.js file from the layout page resolves the issue.

Below is the code snippet for my table:

  <table id="DashboardTab" class="table table-striped rowlink table-hover" data-link="row">
        <tr>
            <th>
                Name
            </th>
            <th>
                Groups
            </th>
            <th>Active</th>
            <th></th>
        </tr>
        
        @{var i = 0;}
        @foreach (var item in Model)
        {
            <tr>
                <td style="display: none">@item.Id</td>
                <td>
                     @Html.ActionLink(item.Name, "Edit", new { id = item.ID })
                </td>
                <td>
                     <i>All</i>
                </td>
                <td>
                    @if (item.IsStd)
                    {
                        @Html.CheckBox("Active" + i, item.IsActive.Value)
                    }
                </td>
                <td style="display: none">@item.IsStandard</td>
                <td>
                    <i class="fa fa-arrows-v" aria-hidden="true"></i>
                </td>
            </tr>
            i++;
        }

    </table>

Any insights on what might be causing this error?

Update: The issue appears to be related to the attribute "data-link="row". This attribute makes the entire row clickable, hence clicking on the checkbox triggers a row click event. How can I make only specific rows clickable and not all?

Answer №1

The issue arose due to the presence of data-link=row in the table. I only needed a few rows to be clickable, so I decided to remove data-link=row from the table and instead added an onclick() event handler like this:

if(item.IsStd){
  <tr onclick="location.href = '@Url.Action( "Edit", "Home",new {id = item.ID})'">
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Updating the content of a window without the need to refresh the page using JavaScript

Is there a way to navigate back to the previous window in chat_user without refreshing the entire page when the back button is clicked? Below is the code I have tried: <a href="" onclick="window.history.go(-1); return false;">back</a> ...

Changing asp net web form action

Here is a web form that I am working on: Current Form: <form id="transactionParameters" method="post" runat="server" action="remote_url.aspx"> <fieldset> <p> <label for="Username">Username:</ ...

CSS-Only tooltip that adjusts size dynamically

Having trouble getting a tooltip to work exactly as desired? I need to implement tooltips for the contents of dynamically built HTML tables. It must be done with CSS only, without relying on JavaScript or events for performance reasons. The challenge is ha ...

What could be causing jQuery animate to malfunction on mobile devices when a viewport is present?

Everything seems to be working fine on my desktop webpage, but when I try it on mobile, there is no scroll... $("HTML, BODY").animate({ scrollTop: 500 }, 1000); This post suggests that mobile devices may not scroll on the body, but on the vi ...

The vertical tab layout in HTML and CSS is experiencing an issue where the active tab is not being shown above the

Currently, I am developing a web page featuring vertical tabs where each tab corresponds to an image and some content. However, the problem lies in the fact that the active tab is not displaying above the image as expected. In my attempt to resolve this i ...

What are some ways to accomplish this task without relying on a photo editing tool?

Is it possible to swap the image link: https://i.sstatic.net/Wa4mo.jpg with this new link: https://i.sstatic.net/hqVuQ.jpg without having to use a photo editor? Below is the CSS and HTML code: I was unable to upload the logo due to the restrictio ...

Top method for retrieving CSS variable in a customized Angular directive

I have a question regarding the process of converting the statement below to Angular's renderer2: this.elementRef.nativeElement.style.setProperty( '--primary-color ' , '#455363' ) The above statement modifies a CSS variable in the ...

Struggling with Responsive Design Challenges with Grid Material UI?

Encountering an issue while using the Grid Component in my React JS Project. Let's delve into some code and then I'll explain what I aim to achieve with images: Assuming this is the rendered code: <div style="margin:100px 20%; width:80%" &g ...

What is the method for adjusting the success button's color using SASS?

My current theme's success button is green, but I want to change it to yellow. How can I achieve this? In the _variables.scss file, the following lines are present: $btn-success-color: $btn-default-color !default; $btn-success-bg: ...

Is it possible to generate multiple modal windows with similar designs but varying content?

I am facing a challenge with 140 link items that are supposed to trigger a modal window displaying a user profile for each link. The issue is that each user profile contains unique elements such as three images, a profile picture, text paragraph, and socia ...

Can someone assist me in understanding how to manipulate dictionaries with the format <string, char> in C#?

In my C# project (Windows Forms App in Visual Studio 2017, .NET Framework), I am facing a challenge with using a Dictionary in a "string, char" format. This is what I have: Firstly, a dictionary in the following format: Dictionary<String, char> bi ...

What could be causing my CSS to malfunction when I include two parameters in app.get?

While developing an express app, I encountered an issue where my CSS code stopped working whenever I added an ":ID" parameter to the URL. It seems like a filepath problem because bootstrap is still loading fine, but on the specific page with the ID paramet ...

What is the best way to incorporate code into a page with numerous conflicting CSS styles, without resorting to Scoped CSS?

Struggling to incorporate tab code into a page with conflicting CSS? Even after attempts to edit classes and labels, the original code fights back against the new additions. While scoped CSS seems like the perfect fix, it's not widely supported yet. ...

tips for generating a random number for direct display

Can anyone help me figure out how to automatically display the total of numbers from this script on my blog post without having to click anything? Additionally, I need it to update if the browser is refreshed. ` http://jsfiddle.net/BenedictLewis/xmPgR/ ...

I am struggling to make the sticky-top navbar overlap with the following element in Bootstrap 4

UPDATE: see an example of the desired effect here SECOND UPDATE: The solution turned out to be quite simple. I had separated my header and footer into a different file and mistakenly placed the navbar outside the body tag. Moving it inside the body tag, s ...

Alignment of Nested Accordions using BootStrap: Right Justified

I have a nested accordion that resembles the following structure: https://i.sstatic.net/HT6kS.png However, I am seeking to align them to the right so that all collapse arrows are in line. In my Plotly Dash implementation, the code looks like this: d = {& ...

Display or conceal content based on checkbox status

i am trying to create a system where content is hidden by default and only displayed when a checkbox is checked. The goal is to show the content when the checkbox is checked and hide it when unchecked, so that other content can be shown as well upon checki ...

Create a right-to-left (RTL) CSS file within a create-react-app project and dynamically switch between them depending on changes

I am currently working on a multi-language project using create-react-app. My goal is to incorporate a library like "cssJanus" or "rtlcss" to transform the Sass generated CSS file into a separate file. This way, I can utilize the newly created file when sw ...

Switch between showing and hiding a div by clicking on the panel header and changing the symbol from + to

I need assistance with a panel feature on my website. The panel should expand when the "+" symbol is clicked, displaying the panel body, and the "+" symbol should change to "-" indicating it can be collapsed by clicking it again. There is a slight twist t ...

Dynamic way to update the focus color of a select menu based on the model value in AngularJS

I am looking to customize the focus color of a select menu based on a model value. For example, when I choose "Product Manager", the background color changes to blue upon focusing. However, I want to alter this background color dynamically depending on th ...