Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Special characters in JavaScript parameter strings

Must display properly and still be used by JavaScript



1:06 pm on Apr 11, 2002 (gmt 0)

10+ Year Member

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.



6:14 pm on Apr 12, 2002 (gmt 0)

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

Why not just have two strings?

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


6:56 pm on Apr 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

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).





Featured Threads

Hot Threads This Week

Hot Threads This Month