homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Gold Sponsor 2015!
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Special characters in JavaScript parameter strings
Must display properly and still be used by JavaScript

10+ Year Member

Msg#: 82 posted 1:06 pm on Apr 11, 2002 (gmt 0)

Hi Guys,

I am calling a Java Script function on OnClick event. The function takes 4 input parametes. One among the four parameter is String. Which contais some spcial characters like ",',<,>.

I have written a function to handle the ' and " . The function converts the those charaters into Escape Sequences. It's working fine.

And also i have written a method to convert the <,> into Entity Reference. This method is giving solution for HTML display. But when i am using the converted string for Java Script alert it displaying as a Entity Reference charateres it self.


The orginal String is <prabhu's>
Converted one & lt;prabhu\'s& gt;
Display in Java Script alert is & lt;prabhu's& gt; i have used spaces inbetween Entity Reference charates.

Now i need a function. Which one is having the ability to take care of Display inside the HTML page as well as in Java Script alert without displaying charaters as Entity Reference charater.




WebmasterWorld Senior Member drdoc us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 82 posted 6:14 pm on Apr 12, 2002 (gmt 0)

Why not just have two strings?

String1 = &lt;prabhu\'s&gt;
String2 = <prabhu's>


WebmasterWorld Senior Member 10+ Year Member

Msg#: 82 posted 6:56 pm on Apr 12, 2002 (gmt 0)

DrDoc has the answer above as you are essentially formatting the strings for two different mediums. You could add an extra parameter to your function called something like forHTML.

If this is false then don't replace the <> characters otherwise do (or vice-versa depending which you want to be the default).




Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved