SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question To pass special characters in a javaScript function.

    Hi,

    I need to pass some special characters as a parameter in a javaScript function and I want them back in the same format inside my function.
    My code is:

    <html>
    <head>
    <script type="text/javascript" >
    function passCharacters(param){
    alert('hi!!::: ' +param);
    }
    </script>
    </head>

    <body>
    <input type="button" value="Click me" onClick="passCharacters(' ')" />
    </body>
    </html>

    I get ' ' in the alert, while I want ' ' in the alert.

    Any help would be appreciated.

    Thanks in advance.

  2. #2
    SitePoint Zealot
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change the charset to iso-8859-1

  3. #3
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Thanks for your reply. Can you please tell me how to do that?
    Thanks in advance

  4. #4
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The code I have written above is just an example but
    In my current scenario, I cant change the charset for the page, but if there is any way to change charset inside a javaScript function, that may help me

  5. #5
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have checked with follwoing code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <script type="text/javascript" >
    function passCharacters(param){
    alert('hi!!::: ' +param);
    }
    </script>
    </head>

    <body>
    <input type="button" value="Click me"
    onClick="passCharacters('&#00211;&#00203; &#00215;&#00192;&#00209;&#00206;&#00194;&#00192;')" />
    </body>
    </html>

    But still I have the same problem

  6. #6
    SitePoint Zealot
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works in all browsers for me.
    An alternative is to use Unicode:
    Code:
    passCharacters('\u00D3\u00CB &#215;....')"

  7. #7
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In muy problem above both the strings are displayed as '&#211;&#203; &#215;&#192;&#209;&#206;&#194;&#192;' only.
    Rather I am sending the parameter as #00211;#00203; #00215;#00192;#00209;#00206;#00194;#00192; (There is & before every #).
    If I add the & before # then wi will display it as &#211;&#203; &#215;&#192;&#209;&#206;&#194;&#192;, rather I want it in number format

  8. #8
    SitePoint Zealot
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want it in number format

  9. #9
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just tried
    <html>
    <head>

    <script type="text/javascript" >
    function passCharacters(param){
    alert('hi!!::: ' +param);
    }
    </script>
    </head>

    <body>
    <input type="button" value="Click me"
    onClick="passCharacters('\u00D3\u00CB')" />
    </body>
    </html>

    But In my alert I again got &#211;&#203;, while I want it in decimal format.

    Also In my case I am getting this String from server as "#00211;#00203; #00215;#00192;#00209;#00206;#00194;#00192;" , So I cant change it to Unicode

  10. #10
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I add amp; in between every & and # in my parameter, then it works fine.
    But I cant even do that.

    I tried to use replace to edit my javascript parameter
    <xsl:value-of select="replace({$Str},'&','&amp;')"></xsl:value-of>
    But I get the error that entityReference & must be followed by entityName


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •