Solved

apostrophe in Javascript array

Posted on 2003-12-12
2
1,339 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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
recommended CMS for the website revamp 3 99
Problem to run file 9 126
Swiper slider stops between pages 11 51
Animated .jpg? 13 97
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

827 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