Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem with special characters

    Hello everyone,

    I am relatively new to scripting. I am using javascript in ASP pages.
    I have an encoding problem with Javascript to display special characters.
    I extract the data from my xml file.
    Here is a label from my xml file
    <LblCompany>Société</LblCompany>
    I have a function called GetText("LblName") that returns the corresponding string with the label name.
    When I do GetText("LblCompany") it returns me Société
    Now i want the above text to be seen in javascript alert as "Société".

    I can't figure out how do i handle the é to be shown as "é"!

    I have tried to use Escape and Unescape functions but don't seem to get the result as expected.

    When I apply Escape function to alert(escape("<%=GetText("LblCompany")%>")) it returns me
    Soci%26%23233%3Bt....
    I am aware that using Unescape would show "&" and other related chars.

    Can someone please tell me how to get this sorted out?

    Thanks

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Just some ideas...

    Did you try just doing this?
    alert("<%=GetText("LblCompany")%>")
    Is that returning wrong results?

    If so look at the generated source code.
    Are the special characters showig up correctly in the source of the page?

    Do you have the correct encoding set for the page?
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi there,

    Yes the special characters do show up right on the page.
    For instance if i say alert("Société"); it does appear right. But now when I am inside my asp page the gettext() function which is written in vbscript extracts the data as Soci%26%23233%3Bt....
    But this does show the expected characters on the page if the language is vbscript. Now if i change the language of the page to javascript and use the vbscript tags(<%%>) in them and show the same text, then this text is not converted to the special char "é"

    One of my friends suggested me to use decodeURI but in vain.

    The bottomline is that the text shows up right when the language is vbscript but doesn't show up when it is javascript.

    My javascript is not able to convert the "&"s "%"s and other special characters.

    What do you mean my having correct encoding set for the page? You mean to say under tools - internet options - advanced options?

    Any other suggestions?

    Thank You

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    What I mean by encoding:
    http://www.w3.org/International/O-charset

    unescape and decodeURI only change certain characters and that is why it is not working.

    I think you are going to have to write your own function that converts that characters over, unless someone else here knows any other solution.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

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