An issue arises in Javascript when attempting to select a row in a gridview by clicking

I have recently implemented a click event for the rows in a devexpress gridview on the server-side using VB.net.

 Protected Sub gvSubNotes_HtmlRowPrepared(sender As Object, e As ASPxGridViewTableRowEventArgs)
    e.Row.Attributes.Add("onclick", String.Format("OnEntryClick('{0}', '{1}', '{2}', '{3}');", e.GetValue("ID"), e.GetValue("SYNOPSIS"), e.GetValue("ENTRY"), e.GetValue("ENTERED_BY")))
 End Sub

However, I encountered an error on the client side when attempting to click. The source in Chrome DevTools displayed:

<tr id="gvSubNotes_DXDataRow0" class="dxgvDataRow" onclick="OnEntryClick(&#39;1375&#39;, &#39;Forager&#39;, &#39;UPDATED on 9/12/2023 8:39:07 AM: UPDATED on 9/12/2023 8:36:32 AM: Trying to scrape up a sub for lunch.&amp;nbsp; &amp;nbsp;i mean for subs.&amp;nbsp; yeah that&#39;s it.&#39;, &#39;DJANGO&#39;);" onmouseover="OnEntryMouseOver(this);" onmouseout="OnEntryMouseOut(this);" style="background-color:White;">
   <td class="dxgv" style="color:Black;background-color:Beige;">9/11/2023</td> <!--ERROR HERE -->
   <td class="dxgv dx-ellipsis" style="color:Black;">Forager</td>
   <td class="dxgvPHEC dxgv" style="color:Black;background-color:Beige;">DJANGO</td>
   <td class="dxgvHEC"></td>
</tr>

The issue was identified as "Uncaught SyntaxError: missing ) after argument list" at the first td field of the row.

This is my first encounter with this problem despite having implemented similar functions in the past. I would appreciate some assistance in spotting where I may have gone wrong. Thank you for any help provided.

Answer №1

When using the GetValue method in your example, you may encounter a string with a single quote in the middle, such as "that's it", which can disrupt the string formatting.

Depending on the expected values, you have the option to either use double quotes or sanitize the string values before constructing the function call by removing any single quotes.

e.Row.Attributes.Add("onclick", String.Format("OnEntryClick('{0}', '{1}', '{2}', '{3}');", e.GetValue('ID'), e.GetValue('SYNOPSIS').replace("'", ""), e.GetValue('ENTRY').replace("'", ""), e.GetValue('ENTERED_BY')))

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

Tips on creating unit tests for AngularJS attribute-type directives using Jasmine

I have a directive that doesn't use any template or templateUrl. How can I write a unit test for this directive? Below is the code for my directive. var app = angular.module('SampleDirective'); app.directive('sampleContent', [fun ...

When attempting to compile Angular in production mode, errors may arise such as the Uncaught SyntaxError caused by an Unexpected token '<'

I encountered some errors in the console of my Angular 8 app. When I opened the browser window, it was blank and this error appeared: Uncaught SyntaxError: Unexpected token '<' https://i.sstatic.net/a16DD.png I tried running different ng bui ...

Mastering the functionality of array.map()

Apologies for the simplicity of my query. I am in the process of streamlining some code and have been exploring the use of array.map rather than traditional for loops to iterate through arrays and using array.push. I've managed to grasp the fundament ...

JavaScript - If you change the properties of an object within an array, does it automatically set the array as needing an update?

If we were to imagine a scenario where there is an array containing 3 objects, and then I decide to access the second object by its index in order to modify one or more of its properties, what would happen? Would this modification mark the entire array a ...

Boost your website's loading time by utilizing the async and defer attributes

Looking to enhance the speed of my webpage, particularly focusing on improving initial page speed. Research suggests that using the async and defer attributes for JavaScript can be beneficial. All JavaScript scripts are currently placed just above the cl ...

What is the best way to calculate the total of all files within a folder structure using JavaScript

Here is the array I'm working with: Array (7812) 0 {foldername: "", amount_of_files: 12, children: 86} 1 {foldername: "/pm", amount_of_files: 3, children: 7} 2 {foldername: "/pm/css", amount_of_files: 1, children: 0} 3 {f ...

integrating jquery with Ruby on Rails version 3

I am facing an issue in my rails application where I am trying to implement a jQuery effect. Specifically, I want a button that will hide the content within a paragraph tag when clicked. Despite trying various approaches, I have been unable to get it worki ...

Does the success callback for AJAX operate synchronously?

Understanding that AJAX is asynchronous, a common question arises regarding the event execution within the success callback. Consider this scenario: $.ajax({ url : 'example.com', type: 'GET', success : (dataFromServer) { ...

What is the best way to retrieve selected text in an editor from an external source?

Is there a way to retrieve selected text from an editor that was originally highlighted outside of the editor? I have tried using editor.getSelection().getSelectedText() but it doesn't seem to be working. Any suggestions on how to accomplish this? ...

Using Jest to verify whether a specific class instance in JavaScript/Typescript calls a function

Currently, I am running tests on express middlewares using jest. it("should throw 400 error if request.body.id is null", () => { const req = { body: { id: null } } as any; const res = {} as any; const next = jest.fn(); myMiddle ...

Is there a way to link the scrolling of two ag-grid data tables together for synchronized movement?

I have integrated ag-grid into my Angular project and I am looking to display two data tables (ag-grid) stacked on top of each other. Both data tables should scroll together, meaning when I scroll in table 1 or table 2, the content of both tables should m ...

Encountering issue with building/deploying a node application on Red Hat OpenShift due to the error message "Unable to resolve output image"

After linking my GitHub repo to an OpenShift app and adding the necessary properties to package.json, I encountered an issue with the Builds section. The status message reads "Output image could not be resolved" and it shows that the build has not starte ...

In Typescript, what is a function that can return multiple types separated by commas known as?

As someone who is new to Typescript, I recently came across the following syntax: interface Foo { // what does age signify and // what if it is not optional i.e () => string, age:number; (): () => string, age?: number; } From what I ...

Is there a way to select multiple elements with the same class using getElementByClassName instead of only obtaining the first element with that class designation?

I recently started learning JavaScript, and I'm still struggling to grasp many concepts. I'm currently working on styling buttons on my website to match the existing ones, but I'm unable to edit the plugin's HTML directly. I was able to ...

Safari's Failure to Execute Ajax Requests

My HTML page includes an ajax request that is functioning properly on Firefox, but does not work on Safari. While debugging, I noticed that the readystate is undefined and the status is "". Can anyone suggest why it might not be working on Safari? Javascr ...

Submitting an extremely large string to an Express server using JS

How can a large String be efficiently sent to a Node.js Express server? On my webpage, I am using Codemirror to load files from an Express server into the editor. However, what is the most effective method for sending "the file" (which is actually a bi ...

Verify if the expression can be found in the DIV element's style

Recently, I encountered a situation where a DIV contains a background image that is either set directly or generated as an SVG. I needed to figure out how to determine when the DIV contains the SVG-string. Here are my two DIVs: <div class="cover m ...

Guide on how to navigate users to a new page using react-router-dom v6 within a class-based component

I am facing an issue where I need to redirect the user to '/dashboard' after logging in, but I do not want to use history.push() from react-router-dom v5.2.0 as I have react-router-dom v6 installed. Is there another alternative to achieve this re ...

CSS trick for masking line borders with parent corner radius

I'm currently utilizing next js for my web application, and I have encountered a specific requirement that needs addressing. You can find the visual representation of this requirement in the following image: https://i.sstatic.net/zGVrl.png The progr ...

What is the best way to sort a group of objects in a parent class depending on the specific subclass that is instantiated?

Trying to simplify things for better understanding, I have designed an object hierarchy. My goal is to tweak the GetFeatures() function so that it only retrieves the features added by the constructor of the specific object type I create. For instance, if ...