HighDots Forums  

Removing ampersand - regular expresion replace with javascript

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss Removing ampersand - regular expresion replace with javascript in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jon
 
Posts: n/a

Default Removing ampersand - regular expresion replace with javascript - 04-27-2006 , 08:15 AM






Hi, I would like to remove ampersands from text and repace them with
the HTML special character.

This is so that I can use them in a query string.

This is my code but it doesn't work, can you see a problem with it?

//if have needed to escape the string for previous operations

textarea.value=unescape(textarea.value);
content = textarea.value;
content = content.replace("&","&");

Thanks in adance

Jon


Reply With Quote
  #2  
Old   
David Lee Lambert
 
Posts: n/a

Default Re: Removing ampersand - regular expresion replace with javascript - 05-04-2006 , 02:43 PM






Jon wrote:
Quote:
Hi, I would like to remove ampersands from text and repace them with
the HTML special character.

This is so that I can use them in a query string.

This is my code but it doesn't work, can you see a problem with it?

//if have needed to escape the string for previous operations

textarea.value=unescape(textarea.value);
content = textarea.value;
content = content.replace("&","&");
Have you tried quoting the ampersand (which is also an SGML special
character)?:

content = content.replace("&","&");

Also, are you sure you're using the "content" variable afterward properly?



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.