Solved

apostrophe in Javascript array

Posted on 2003-12-12
2
1,343 Views
Last Modified: 2012-06-27

Hi

I have a javascript array that i use to populate combo boxes on my asp page. The string values i have in there may occasionally contain apostrophes such as the Italian town shown below.

MyArray[0][1] = new Option('Citta Sant'Angelo area');

However this causes errors as the array gets confused with the apostrophe in the string and thinks that it represents the end of the string.

In VB you can do a Replace(MyString, " ' ", " ' ' ") to fix this sort of problem on sql inserts etc...

Is there something similar i can do in Javascript as it is not preferable to simply remove the apostrophes.

Many thanks in advance

Kels
0
Comment
Question by:Kels
2 Comments
 
LVL 12

Accepted Solution

by:
ahosang earned 200 total points
ID: 9927840
You can do it in the form:
MyArray[0][1] = new Option("Citta Sant'Angelo area");

or:
MyArray[0][1] = new Option('Citta Sant\'Angelo area');
0
 

Author Comment

by:Kels
ID: 9927853
Actually i had just found that myself, i didn't realise you could use double quotes.

Thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
XSLT 5 49
Hide or Show Images using checkbox array in mysql database 11 291
I starting with php 12 139
Grunt No Clean Targets 6 232
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question