Tips on sending a string as an argument in an onclick function

I am currently attempting to automatically add an anchor, and here is what I have tried:

" <a  id='" + x.NomFic + "' onclick='TransfererFica( " +x.Idtran +"  ,  "+ x.NumVdr + "  , '" + x.NomFic + "' )';   </a>"

Unfortunately, the issue arises because x.NomFic is a string. When I click on the anchor, it results in an error. So, my question is how can I pass a string parameter? I attempted to use an integer instead just to test if my code works, and it did. However, when I changed x.NomFic to accept a string, the code stopped working. Do you have any ideas on how to resolve this issue?

Answer №1

To properly escape characters in your code, make sure to use the escape character "\"

" <a  id='" + x.NomFic + "' onclick='TransfererFica( " + x.Idtran + "  ,  " 
       + x.NumVdr + "  , \"" + x.NomFic + "\" )';   </a>"

For further information on escape characters, check out this resource.

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

Enforce multi-login restrictions within an Asp.net environment

I am facing an issue where if "User A" logs in from one computer using "ABC" credentials, and then "User B" logs in from another computer with the same credentials, "User A" gets kicked out of their account. I have attempted to solve this using session id ...

Oops! You're trying to render a Next.js page using a layout that has already been declared

I have created two different layouts in Next.js - MainLayout and DashboardLayout. import Navigation from '../Navigation'; export default function MainLayout({ children }) { return ( <> <Navigation links={[ ...

Adding a backslash in Angular: Tips and Tricks

I have a question about adding a backslash to a string that is returned from a div, for example Car1 \sold. Although I am able to retrieve the status, I am having trouble adding the backslash. Here is what I have tried so far: <span>{{addBackl ...

I'm unsure of the most efficient way to condense this statement

$(document).ready(function(){ if ($(window).width() <961){ $('.item').on('click',function(){ /*---do something---*/ }) }else{ $('.item').on('click',function(){ ...

Trouble keeping HTML/Javascript/CSS Collapsible Menu closed after refreshing the page

My issue is that the collapsible menu I have created does not remain closed when the page is refreshed. Upon reloading the page, the collapsible menu is always fully expanded, even if it was collapsed before the refresh. This creates a problem as there is ...

The error message states that `article.createdAt.toLocalDateString` is not a valid

const mongoose = require("mongoose"); const blogPostSchema = new mongoose.Schema({ title: String, image: String, description: String, createdAt: { type : Date, default : new Date() } }); const blogPos ...

Issue with Bootstrap 5: Mobile Menu Failure to Expand

I’ve been struggling with this issue for days now. I’ve searched everywhere for a solution, but to no avail. That’s why I’m turning to the experts here for help :-) The problem I’m facing is that my mobile menu won’t open. Nothing happens when ...

Reactive Form value is not displaying in view because of FormControlName issue

I have successfully retrieved data from the database and need to pre-fill an update form with preset values. The issue I am facing is that when I add FormControlName to the input field, it removes the preset values. I have tried using setValue and patchV ...

Regular expressions are used for validation purposes

I've been using the regular expression shown below to validate certain text: ^\d+(?:fs|sf)[-+]\d+[hmd]$/ Here are some sample texts I have validated with this regular expression: 20fs-4d 10sf+20m 3fs-2h So far, it's been working we ...

Struggling to get getInitialProps working in dynamic routes with Next.js?

I am encountering an issue. The return value from the getInitialProps function is not being passed to the parent component. However, when I console.log the values inside the getInitialProps function, they appear to be correct. Here is the code snippet: i ...

The toggle button requires two clicks to activate

I created a toggle button to display some navigation links on mobile screens, but it requires two clicks upon initial page load. After the first click, however, it functions correctly. How can I ensure that it operates properly from the start? Below is t ...

Creating a Countdown in Javascript Using a Variable

I want the date to change from the first date to the second date. At the start, it should display 'Starts:' in bold followed by the remaining time. Once it switches to the second date, it should show 'Ends:' in bold and then the remaini ...

What is the process for converting [AnonymousType#1] or setting it in advance?

I encountered an issue: Cannot implicitly convert type 'System.Linq.IQueryable<AnonymousType#1>' to 'System.Linq.IQueryable<object>' This error is new for me while working with .NET 3.5. I am uncertain about what caused th ...

How do you trigger a function in a child component that was imported when a parent element is clicked?

Is it possible to access and call a function in an imported component from the "parent element"? I have multiple modules that I want to include dynamically in my app. I thought that if I import a component like Header in my main App.vue file, it would reco ...

Issue with video.js text track memory leakage (WebVTT/VTT)

I am utilizing Video Text Tracks to showcase advanced live information on top of the video. A new video is loaded every few minutes, each with its own .webvtt file (consisting of 2-3k lines). Although everything is functioning properly, there is a persis ...

Utilizing arrays in Expressjs: Best practices for passing and utilizing client-side arrays

Here is the structure of an object I am dealing with: editinvite: { _id: '', title: '', codes_list: [] } The issue I am facing is that I am unable to access the codes_list property in my NodeJS application. It appears as 'u ...

Activate JavaScript functions by pressing the enter key, allowing for various searches, AJAX requests, and DataTable displays to occur seamlessly without the need to refresh

I recently developed a web page that integrates an AWS API interface to interact with an RDS Aurora MySQL Serverless database. Users can input a SQL statement and click the Query button, which triggers an AJAX request, returns JSON data, and converts the d ...

Having difficulties parsing CSV file encoded in ANSI using CSVHelper

I am facing an issue while using CSVHelper to read a CSV file that includes special characters like the GBP symbol (e.g. £2000). Unfortunately, during the processing of the file, the pound symbol is not displayed correctly and instead shows up as a diamo ...

Send data in JSON format along with an identifier using Jquery AJAX

I am having trouble sending JSON data along with 2 IDs using a jQuery AJAX post. Despite my efforts, I can't seem to get it working. Here is the code snippet in question: try { var surveyID = localStorage.getItem("surveyId"); var userDetails ...

Breaking up and processing a given string in JavaScript: Splitting and token

When it comes to dealing with this specific JavaScript requirement, the challenge lies in working with a string such as: “ [ condition12 (BRAND) IN 'Beats by Dr. Dre & D\’Silva of type Band’ of type 'IDENTIFIER_STRING’ ] ...