Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » XmlHttpRequest and friends

Credits go to FMC, Jonny Cook, and miran for helping out!
This thread is locked; no one can reply to it. rss feed Print
 1   2 
XmlHttpRequest and friends
Matthew Leverton
Supreme Loser
January 1999
avatar

Are you sure it's truncated, or is the alert box just not displaying it all?

Quote:

alert() doesn't have troubles with accented letters.

No, but the encoding might get lost. How is it encoded on the server? UTF-8? If so, you'll need to convert them to JS's "\u1234" format. As a quick hack, you could use PHP's utf8_decode() function, but that will only help for chars < 256.

Marco Radaelli
Member #3,028
December 2002
avatar

Quote:

Are you sure it's truncated, or is the alert box just not displaying it all?

I guess so, because if I use eval() IE pops up an error saying 'Unterminated string...'.
Err... wait, that's what it kept saying on my home computer, here in university there seems to be another error: it says that 'select' is undefined, but only if I run the javascript more than once.

To sum it up I have two drop-down menus. The content of the latter depends on the selected item of the former.

When an element is selected, I delete all the content of the former <select> with

 select = document.getElementById('comune');
 
 for(i = 0; i < select.options.length; i++)
   select.remove(i);

This works when it contains only one element, but fails if its content has been filled through the javascript server-generated. I'm investigating it, any idea?

Quote:

No, but the encoding might get lost. How is it encoded on the server? UTF-8? If so, you'll need to convert them to JS's "\u1234" format. As a quick hack, you could use PHP's utf8_decode() function, but that will only help for chars < 256.

Resolved :), I just made the php script output the charset along with the content type in the HTTP Response header
header("Content-type: text/javascript; charset=iso-8859-1");

[edit]

Wohoo :D

this is the way to remove all the <option>s

 while(select.options.length)
   select.remove(0);

not this

 for(i = 0; i < select.options.length; i++)
   select.remove(i);

 1   2 


Go to: