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 7 of 7
  1. #1
    New Coder
    Join Date
    Jun 2009
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    hebrew in javascript - display nothing

    Hello

    In my asp page I successfully extracted records from my database written in Hebrew. I used <% @ codepage=65001 %> and <% Response.Charset= "utf-8" and it worked. then i join all the values to one array using "x = join(myArry,"|") ". I printed the results and it was ok so far. the problem begin in the JavaScript block. in which i used the split command like this
    arr=new Array();
    var subbs="<% = x%>"
    arr = subbs.split("|");

    but from some reason when im printing the array i got nothing as a result
    for(i=0; i<arr.length; i++)

    document.write("element " + i + " : " + arr[i] + "<BR />");

    When I was doing the same without the Hebrew records from DB, but with simple array that contains just numbers, it works fine (x = "1,2,33,4,5" )
    So I assume my problem happened because of the Hebrew and i don't know how to fix it...can someone please advice?

    Thank you

  • #2
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    Try putting this in your html file (.asp file) inside the header.

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  • #3
    New Coder
    Join Date
    Jun 2009
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you very much. I put “<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> ” inside the header and saw that javascript deals good with hebrew.
    Inside my asp code I initialized the variable Dim x= "שלום|אבא|אמא|ילד|בית" with Hebrew strings separated by “|” and the split func in javascript works ok and display the Hebrew string

    Now I see that my problem begins when my asp array is created by records selected from my DB, instead of initializing the "x" string with predefined strings as described above
    I extracted the records successfully and use the func "join" to convert the asp array to string so I can later use it in the "split " func in javascript as before - that is no longer works ok and I wonder why.
    I suppose that it is related to the fact I’m getting the data from DB, cause when I’m originally initializing asp variable “x” with the predefined data as appear exactly in the DB it works ok (without all the BD procedure )
    Does anyone have an idea how to solve it? The code described below
    I hope I was clear in describing my problem…


    <META HTTP-EQUIV="Content-Type" CONTENT="text/html"; charset="windows-1255">

    <html>
    <HEAD DIR=RTL>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    </head>
    <BODY DIR=RTL>
    <% @ codepage=65001 %>
    <% Response.Charset= "utf-8"

    Dim adoCon 'Holds the Database Connection Object
    Dim rsGuestbook 'Holds the recordset for the records in the database
    Dim strSQL 'Holds the SQL query to query the database
    Dim x
    ‘Dim x1 = "שלום|אבא|אמא|ילד|בית"


    'Create an ADO connection object
    Set adoCon = Server.CreateObject("ADODB.Connection")

    'Set an active connection to the Connection object using DSN connection
    adoCon.Open "DSN=my_db"
    'Create an ADO recordset object
    Set rsGuestbook = Server.CreateObject("ADODB.Recordset")

    'Initialise the strSQL variable with an SQL statement to query the database
    strSQL = "SELECT guests.Name FROM guests;"
    'Open the recordset with the SQL query
    rsGuestbook.Open strSQL, adoCon


    Dim myArry(2)
    Dim counter=0

    Do Until counter=3

    myArry(counter) = rsGuestbook.Fields("Name")

    counter=counter+1
    rsGuestbook.MoveNext
    loop

    x = join(myArry,"|")
    ‘Response.Write(x) successfully print the records in hebrew

    'Reset server objects
    rsGuestbook.Close
    Set rsGuestbook = Nothing
    Set adoCon = Nothing


    %>
    <script type="text/javascript" charset="windows-1255">
    substring=new Array();
    var subs="<% = x%>"

    //split the String into an array
    substring = subs.split("|");
    for(i=0; i<substring.length; i++){

    document.write("element " + i + " : " + substring[i] + "<BR />");
    }



    </SCRIPT>


    </body>
    </html>

  • #4
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    I am not an expert in ASP but take a look at this link, it might help:
    http://dev.ektron.com/kb_article.aspx?id=594

  • #5
    New Coder
    Join Date
    Jun 2009
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank again.
    The problem with using DB in the asp code, is that it seems not executing the javascript block at all. like a problem in the order of execution which is not happen when i'm using hard coded x (in the hard coded case after the asp execution, the javascript took action) When replacing to BD in the asp code I also put "document.write("hello")" in the javascript code that was never display
    Can u please think of a reason for that?

    BR
    Sara

  • #6
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    First of all you got two meta lines:
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html"; charset="windows-1255">

    <html>
    <HEAD DIR=RTL>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    Then there is this encoding in the javascript input:
    <script type="text/javascript" charset="windows-1255">


    The browser is being lost.
    Try to remove everything that is related to windows-1255 and replace it with utf-8.
    In fact the meta directs the browser to choose the encoding but does not force it.
    So you have to choose in the menu of the browser: view/encoding/auto detect

    Try the above, and if it does not work then please put here the string (x) that is being generated by the query from the database and make sure as well that the database is utf enabled.

    Hope this will solve your problem.
    Last edited by ckeyrouz; 07-03-2009 at 04:24 PM. Reason: Missing information

  • #7
    New Coder
    Join Date
    Jun 2009
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you all - i chaged to utf-8 and it 's working great now


  •  

    Posting Permissions

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