Welcome to WebmasterWorld Guest from 54.167.46.29

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)

New User

10+ Year Member

joined:Mar 1, 2002
posts:6
votes: 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.

ex:-

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.

Thanks!
Prabhu.

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

Senior Member

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

joined:Mar 15, 2002
posts:6807
votes: 0


Why not just have two strings?

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

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 10, 2001
posts:793
votes: 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).

ie.

document.write(formatstring(mystring,true));

alert(formatstring(mystring,false));

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members