Escaping unicode characters!

Discussion in 'ASP General' started by Hans, Aug 25, 2004.

  1. Hans

    Hans Guest

    Hi!

    Can someone explain how ASP works when it comes to unicode characters on the
    querystring? See the testcode below. If you type in a chinese character in
    the first textbox and click "post" the javascript code will change the
    action for the <form> and add the text entered in the first editbox to the
    querystring and then submit the form. Then the value on the querystring (id)
    will be presented in the second textbox.

    1. In my example for example chinese characters will be OK regardless if I
    use the javascript escape or encodeURIComponent. If I check
    alert(escape(document.frm.txt.value)) or
    alert(encodeURIComponent(document.frm.txt.value)); they are certainly not
    the same but IIS seems to fix this anyway. Is this just a coincidence or is
    IIS handling the querystring correct regardless if I use the escape or
    encodeURIComponent? Is the request object doing a implicit unescape for me?

    2. The javascript escape should according to my reference guide not support
    unicode characters but If I run the example below and use escape and type in
    a chinese character it is show correct after I submit. I must be missing
    something here (this maybe is a javascript thing but....)


    '#######Name file test.asp###########
    <%@ Language=VBSCRIPT CodePage=65001%>
    <html>
    <body>
    <meta Content-Type="text/html" Charset="utf-8">
    <form name="frm" action="test.asp" method="post">
    <input type="text" name="txt">
    <input type="text" name="txt2" value="<%=request.querystring("id")%>">
    <input type="button" onclick="run();" value="post">
    </form>

    <script language="javascript">
    function run()
    {
    document.frm.action="test.asp?id=" + escape(document.frm.txt.value);
    //document.frm.action="test.asp?id=" +
    encodeURIComponent(document.frm.txt.value);
    document.frm.submit();
    }

    </script>
    </body>
    </html>
    '#######End file test.asp###########

    Regards
    /Hans
     
    Hans, Aug 25, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike P

    escaping characters

    Mike P, Mar 29, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    384
    Karl Seguin [MVP]
    Mar 29, 2006
  2. Laszlo Nagy
    Replies:
    6
    Views:
    661
  3. Terry Reedy
    Replies:
    0
    Views:
    553
    Terry Reedy
    Jul 1, 2008
  4. M.-A. Lemburg
    Replies:
    0
    Views:
    926
    M.-A. Lemburg
    Jul 2, 2008
  5. Grzegorz ¦liwiñski
    Replies:
    2
    Views:
    1,027
    Grzegorz ¦liwiñski
    Jan 19, 2011
Loading...

Share This Page