• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

UFT-8 Encoding Problem

Status
Für weitere Antworten geschlossen.

fids3

Neues Mitglied
Hello,

I have an input form with 3 Fields.

I pre-set the 1st field with حة (hex \u022d \u0229).

If i copy the value (by javascipt) to the second field, i still can see this 2 arabic characters.

If i display the encoded value in the 3rd field, i get
any surrogate character values

%D8%A9%D8%AD

instead of the expected

%02%29%02%2D

What is wrong with this form ???

Here is the full code. You can copy+paste+try it.

Attention: Inside the code you have to insert a '#' character in front of 1577 and 1581. I didn't find out how to display it here correctly.

HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<TITLE>airports</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="Content-Language" content="ar">
<meta name="language" content="ar"/>

<form name="utf8test" action="http://localhost:8080/unused" method="POST">
    <table width=320 border=1 cellspacing=1 cellspacing=0 bgcolor="#666699">
    <tr>
    <td width="65%" align="right">
        <table><tr>
            <td align="right">ARAB:</td>
            <td align="center"><input type="text" name="utf8input" dir="rtl" lang="ar" value="&1577;&1581;" size=30></td>
            <!--  \u062d\u0629 (Hex) -->
        </tr></table>
        <table><tr>
            <td align="right">COPY:</td>
            <td align="center"><input type="text" readonly name="copyx"  dir="rtl" lang="ar" value="" size=30></td>
        </tr></table>
        <table><tr>
            <td align="right">ENCODED:</td>
            <td align="left"><input type="text" readonly name="encoded" value="" size=30></td>
        </tr></table>
    </td>
    <td width="35%" align="center">
        <table>
            <tr><td align="center"><input type="button" value="COPY+ENCODE" onclick="encode_and_copy(document.utf8test)"></td></tr>
            <tr><td align="center"><input type="submit" value="SUBMIT ACTION" disabled></td></tr>
        </table>
    </td>
    </tr>
    </table>
</form>
    
</html>

<SCRIPT LANGUAGE="JavaScript">

function encode_and_copy(f) {

    f.copyx.value = f.utf8input.value;
    f.encoded.value = encodeURIComponent(f.utf8input.value);
}

//-->
</SCRIPT>

Mod-Edit: code-tags edited - please remember for the next time (XraYSoLo)
Moved: JavaScript - no question for HTML (XraYSoLo)
 
Zuletzt bearbeitet von einem Moderator:
Werbung:
ASCII-Characters can not be encodet. If yout type an whitespace in the uri of an website, it will be transformed to %20. It is the same thing with encoding ASCII-characters anywhere else.
 
Status
Für weitere Antworten geschlossen.
Zurück
Oben