jquery form validator not showing Arabic letters correctly

Discussion in 'JavaScript' started by jfiler20, Apr 1, 2013.

  1. #1
    im trying to use a jquery form validation, and i want the validating text to be arabic.
    the problem is that when i change that phrase in the .js file, it shows squares instead of arabic letters.
    this is my js file:
    $(document).ready(function(){// Place ID's of all required fields here. required =["name","email","country","message",];// If using an ID other than #email or #error then replace it here email = $("#email"); errornotice = $("#error");// The text to show up within a field when it is incorrect emptyerror ="Please fill out this field."; emailerror ="Please enter a valid e-mail.";
    so i want to change the last two lines "please fill..." and "please enter..." to arabic.
    and i already tried adding this code: charset=UTF-8 to the head, it still didnt work
    any ideas how to fix that??
     
    jfiler20, Apr 1, 2013 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    What editor are you using? Are you sure you are actually saving the file as UTF-8? Is your server set to send .js files or your .html files as UTF-8 in the HTTP headers and not ISO-8859-1 (the default on most servers)? did you include the charset on the SCRIPT tag used to include this scripting? (assuming it's in an external file).

    When you said you included that 'in the head' -- in the head of what? The HTML? The HTTP headers?

    Though I'd suggest dropping the jquery asshattery entirely, since if the form or page is big enough or poorly labeled so much you need client side scripting that's redundant to checks you HAVE to perform server-side anyways, there's probably something wrong with the site itself.
     
    deathshadow, Apr 1, 2013 IP
  3. jfiler20

    jfiler20 Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    yes i included the charset in the script and the html head:
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="scripts/validation.js" charset=utf-8" ></script>
     
    jfiler20, Apr 1, 2013 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #4
    That's only half of it -- what about the HTTP headers -- is the server even configured for it? Is your editor? Generally what you set in the files is IGNORED if the server sends it in the HTTP response headers... and if your editor isn't actually saving UTF-8, then you've got real problems.

    Generally speaking setting it in the markup is only useful in local testing, entirely because the HTML "head" is ignored in favor of the HTTP "headers"... most servers default to ISO-8859-1, so you have to either reconfigure apache's ini files to change that, or use a htaccess file for same... or whatever the equivalent is on whatever server software you're hosted on.

    ALSO, does the FONT you're trying to use on the page actually support the characters you are trying to use? Fancy webfonts for example (and even many system fonts for certain OS) don't include anything more than ASCII7 and the Latin-1 set.
     
    deathshadow, Apr 1, 2013 IP
  5. jfiler20

    jfiler20 Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    got it...i changed the encoding of the js file to utf-8 and it worked!
     
    jfiler20, Apr 2, 2013 IP