Display nothing - please help...

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Jul 2009
Posts: 6
Reputation: sara10mor is an unknown quantity at this point 
Solved Threads: 0
sara10mor sara10mor is offline Offline
Newbie Poster

Display nothing - please help...

 
0
  #1
Jul 2nd, 2009
Hello

In my asp page I successfully extracted records from my database. The records are written in Hebrew.
I used <% @ codepage=65001 %> and <% Response.Charset= "utf-8" and the display worked ok inside HTML.
Inside my asp code i joined all the values to one string 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
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 811
Reputation: Airshow is on a distinguished road 
Solved Threads: 115
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: Display nothing - please help...

 
0
  #2
Jul 2nd, 2009
sara10,

It does indeed seem that Hebrew characters are the problem. Javscript is really defined as a "Latin-1" langage. Urlencode() won't help because javascript's unescape() will always convert to Latin-1 (unless things have moved on since my reference book was printed).

What I suggest is that you try serving your string segments into separate <span></span> tags each with its own ID.

With a bit of imagination you may be able to shuffle these spans around with dom methods without ever needing to handle the strings themselves in javascript.

Of course, the success of this depends entirely on what you want do client-side with the text.

If you need to perform string manipulations then it seems you will inevitably(?) end up needing to handle the strings in javascript so back to the same old problem. Same with Ajax techniques because server responses would need to be handled by javascript.

Thinking out loud, maybe there are two ways to meet a string manipulation requirement:
  • Do it server-side then re-serve the page (if the Hebrew posts/gets reliably?)
  • Work with character images rather than text.
On that last point, I recently learned of a technique here on Daniweb which may be relevant here (I can't recall the details but should be able to rediscover the topic).

I'm sure you're not the first "non-Latin" to ask this question. Try Googling a query to see what others have done before.

Just a bunch of thoughts I'm afriad.

Airshow
50% of the solution lies in accurately describing the problem!
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 6
Reputation: sara10mor is an unknown quantity at this point 
Solved Threads: 0
sara10mor sara10mor is offline Offline
Newbie Poster

Re: Display nothing - please help...

 
0
  #3
Jul 2nd, 2009
Thank you . I eventually put the “<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…

  1. <META HTTP-EQUIV="Content-Type" CONTENT="text/html"; charset="windows-1255">
  2.  
  3. <html>
  4. <HEAD DIR=RTL>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6.  
  7. </head>
  8. <BODY DIR=RTL>
  9. <% @ codepage=65001 %>
  10. <% Response.Charset= "utf-8"
  11.  
  12. Dim adoCon 'Holds the Database Connection Object
  13. Dim rsGuestbook 'Holds the recordset for the records in the database
  14. Dim strSQL 'Holds the SQL query to query the database
  15. Dim x
  16. ‘Dim x1 = "שלום|אבא|אמא|ילד|בית"
  17.  
  18.  
  19. 'Create an ADO connection object
  20. Set adoCon = Server.CreateObject("ADODB.Connection")
  21.  
  22. 'Set an active connection to the Connection object using DSN connection
  23. adoCon.Open "DSN=my_db"
  24. 'Create an ADO recordset object
  25. Set rsGuestbook = Server.CreateObject("ADODB.Recordset")
  26.  
  27. 'Initialise the strSQL variable with an SQL statement to query the database
  28. strSQL = "SELECT guests.Name FROM guests;"
  29. 'Open the recordset with the SQL query
  30. rsGuestbook.Open strSQL, adoCon
  31.  
  32.  
  33. Dim myArry(2)
  34. Dim counter=0
  35.  
  36. Do Until counter=3
  37.  
  38. myArry(counter) = rsGuestbook.Fields("Name")
  39.  
  40. counter=counter+1
  41. rsGuestbook.MoveNext
  42. loop
  43.  
  44. x = join(myArry,"|")
  45. ‘Response.Write(x) successfully print the records in hebrew
  46.  
  47. 'Reset server objects
  48. rsGuestbook.Close
  49. Set rsGuestbook = Nothing
  50. Set adoCon = Nothing
  51.  
  52.  
  53. %>
  54. <script type="text/javascript" charset="windows-1255">
  55. substring=new Array();
  56. var subs="<% = x%>"
  57.  
  58. //split the String into an array
  59. substring = subs.split("|");
  60. for(i=0; i<substring.length; i++){
  61.  
  62. document.write("element " + i + " : " + substring[i] + "<BR />");
  63. }
  64.  
  65.  
  66.  
  67. </SCRIPT>
  68.  
  69.  
  70. </body>
  71. </html>
  72.  

Thank
Sara
Last edited by Ezzaral; Jul 2nd, 2009 at 6:02 pm. Reason: Added [code] [/code] tags. Please use them to format any code that you post.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 811
Reputation: Airshow is on a distinguished road 
Solved Threads: 115
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: Display nothing - please help...

 
0
  #4
Jul 2nd, 2009
So Javascript handles hard-coded Hebrew served as UTF-8. That's promising.

Now try putting both hard-coded and database-retreived Hebrew directly onto the page. See if there's any difference.

Airshow
50% of the solution lies in accurately describing the problem!
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 6
Reputation: sara10mor is an unknown quantity at this point 
Solved Threads: 0
sara10mor sara10mor is offline Offline
Newbie Poster

Re: Display nothing - please help...

 
0
  #5
Jul 2nd, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 811
Reputation: Airshow is on a distinguished road 
Solved Threads: 115
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: Display nothing - please help...

 
0
  #6
Jul 2nd, 2009
Try this -

  1. <% @ codepage=65001 %>
  2. <% Response.Charset= "utf-8"
  3.  
  4. Dim adoCon 'Holds the Database Connection Object
  5. Dim rsGuestbook 'Holds the recordset for the records in the database
  6. Dim strSQL 'Holds the SQL query to query the database
  7. Dim x
  8. Dim x1 = "????|???|???|???|???"
  9.  
  10. 'Create an ADO connection object
  11. Set adoCon = Server.CreateObject("ADODB.Connection")
  12. 'Set an active connection to the Connection object using DSN connection
  13. adoCon.Open "DSN=my_db"
  14. 'Create an ADO recordset object
  15. Set rsGuestbook = Server.CreateObject("ADODB.Recordset")
  16.  
  17. 'Initialise the strSQL variable with an SQL statement to query the database
  18. strSQL = "SELECT guests.Name FROM guests;"
  19. 'Open the recordset with the SQL query
  20. rsGuestbook.Open strSQL, adoCon
  21.  
  22. Dim myArry(2)
  23. Dim counter=0
  24.  
  25. Do Until counter=3
  26. myArry(counter) = rsGuestbook.Fields("Name")
  27. counter=counter+1
  28. rsGuestbook.MoveNext
  29. loop
  30.  
  31. x = join(myArry,"|")
  32. Response.Write(x) successfully print the records in hebrew
  33.  
  34. 'Reset server objects
  35. rsGuestbook.Close
  36. Set rsGuestbook = Nothing
  37. Set adoCon = Nothing
  38. %>
  39. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  40. <html>
  41. <head>
  42. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  43. </head>
  44. <body dir="rtl">
  45.  
  46. <script type="text/javascript" charset="csISOLatinHebrew"><!-- MIBENUM 11 : ISO-8859-8 -->
  47. document.write("<% = x%>".split("|").join('<br />'));
  48. </script>
  49.  
  50. <script>
  51. document.write("hello1|hello2|hello3|hello4|hello5".split("|").join('<br />'));
  52. </script>
  53.  
  54. </body>
  55. </html>

NOTES:
  • Rearranged the page so all the asp is at the top. You will need to reinsert the hard-coded Hebrew, 'cos my non-savvy editor has destroyed it.
  • Added a doctype (XHTML 1.0)
  • Adjusted the javascript tag's charset to conform with IANA recommendation http://www.iana.org/assignments/character-sets
  • Boiled the javascript code right down to the bare essentials
  • Added a second, vanilla flavoured javascript block doing a very similar task with hard-coded Latin.
Airshow
Last edited by Airshow; Jul 2nd, 2009 at 10:02 pm.
50% of the solution lies in accurately describing the problem!
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 6
Reputation: sara10mor is an unknown quantity at this point 
Solved Threads: 0
sara10mor sara10mor is offline Offline
Newbie Poster

Re: Display nothing - please help...

 
0
  #7
Jul 7th, 2009
Thank you all - i chaged to utf-8 and it 's working great now
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 811
Reputation: Airshow is on a distinguished road 
Solved Threads: 115
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: Display nothing - please help...

 
0
  #8
Jul 7th, 2009
Well done. Charenc issues can be little devils.

Airshow
50% of the solution lies in accurately describing the problem!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC