Solved

apostrophe in Javascript array

Posted on 2003-12-12
2
1,336 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

776 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