Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7984967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:26:17+00:00 2026-06-04T11:26:17+00:00

In my case, I am trying to split the JavaScript Object dynamically into the

  • 0

In my case, I am trying to split the JavaScript Object dynamically into the HTML markup from C#.NET code behind. After getting the data, I prepare the string and create the object in the string and then spit it to the HTML markup.

var fileUploadDic = { 'firstname': 'Jo''hn', 'lastname' : 'Macy' , 'country' : 'USA };

Later on in some other action, such as button click, I tried to pull the firstname, and it gives me a JavaScript error because the value in the firstname property is not escaped to handle the single quote. Although I can do it while preparing the object string in the code backend, I like to do something at the client side instead.

var dv = $('#dv1')
dv.append(fileUploadDic.firstname);  //gives me error.
dv.append(fileUploadDic.lastname);
dv.append(fileUploadDic.country);

Is there any way in the JavaScript, that I can do the character escaping while fetching it from the object.

http://jsfiddle.net/uagFu/8/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:26:19+00:00Added an answer on June 4, 2026 at 11:26 am

    The first line of code you show is not valid JavaScript:

    var fileUploadDic = { 'firstname': 'Jo''hn', 'lastname' : 'Macy' , 'country' : 'USA };
    

    Because the string 'Jo''hn' can’t have single quotes in it like that. It needs to be either 'Jo\'hn' or "Jo'hn". That is to say that if your JS string is quoted with single quotes you have to escape each single quote character within the string with a backslash, but if your JS string is quoted with double quotes you can use singles freely within the string. If you want two single quotes in a row 'Jo\'\'hn' or "Jo''hn".

    There is nothing you can do to fix this client-side, because being invalid JavaScript it won’t run.

    You have to fix it server-side; the easiest way is probably to escape it with a backslash, noting that if that is in a C# string you’ll need to escape the backslash too so that the actual output to the browser contains a backslash:

    "var fileUploadDic = { 'firstname': 'Jo\\'hn', 'lastname' : 'Macy' , 'country' : 'USA };"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my test case I am trying to capture the dynamic state id from
I'm trying to get a case-insensitive search with two strings in JavaScript working. Normally
I'm trying to split a byte stream into chunks of increasing size. The source
I'm trying to convert some code from Python to C++ in an effort to
I am trying to split the text into words: $delimiterList = array(" ", ".",
I'm trying to split up my Django models into separate files but I apparently
I'm trying to find the best way to split data into groups, for example
I am trying to split groups of elements into groups that contain a unique
I am trying to take a data string from one column and split it
I'm currently trying to split a string in C# (latest .NET and Visual Studio

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.