SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Aug 2006
    Location
    NJ, USA
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Foreign language characters not displaying properly in form fields

    I have the following code that displays two text input fields. If I set the value of the form field in HTML directly (Fld1) it converts the HTML codes to valid characters (in this case Arabic characters). However, when I use Javascript to set the value of the form field after the form is displayed, the codes show up as codes and are not converted to the Arabic characters. Any ideas why this happens and how to work around it?

    Code:
    <form action="test.asp" method="post" name="form">
      <table cellpadding="0" cellspacing="0" width="100%">
    	  <tr>
    	    <td align="right" class="textLabel">Test Fld 1:</td>
    	    <td><input type="text" id="Fld1" name="Fld1" size="75" maxlength="200" value="سسسس ششش"></td>
    	  </tr>
    
    	  <tr>
    	    <td align="right" class="textLabel">Test Fld 2:</td>
    	    <td><input class="fldfont" type="text" id="Fld2" name="Fld2" size="75" maxlength="200"></td>
    	  </tr>
      </table>
    </form>
    
    <Script LANGUAGE="JavaScript"><!--
    document.form.Fld2.value = 'سسسس ششش ';
    //--></Script>
    We have written a set of routines where we pass in data in a recordset and the name of a form and it automatically generates the Javascript statements for each form field to fill the data from the recordset. It has worked well until we had to handle characters from other languages.

    Thanks for any advice.
    Dan

  2. #2
    SitePoint Member
    Join Date
    Aug 2006
    Location
    NJ, USA
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please note, the code sample above converted the HTML codes to the actual Arabic characters. When we pull this actual data, it is returned in sets of HTML codes using and "&" and then the HTML code like "#1587". So what we see in the form field in a browser are the HTML codes when we should see the Arabic characters.
    Last edited by netprofit5; Aug 17, 2006 at 08:54. Reason: Additional info

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This works but I wouldn't say it's the best solution:

    Code:
    document.form.Fld2.value = String.fromCharCode(1587,1587,1587,1587,32,1588,1588,1588,32);

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using the Unicode escape for JavaScript (e.g., "\u0633" for "&#38;#1587;").
    Birnam wood is come to Dunsinane

  5. #5
    SitePoint Member
    Join Date
    Aug 2006
    Location
    NJ, USA
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies. jimfrasers idea worked great. Since we're pulling this data from a database, we had to strip out the special codes (&, #, to just use the numbers but that was easy.


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
  •