I am currently working on a user registration PHP script. On the client-side I've included an AJAX application that dynamically updates the states/provinces/municipalities based on the country selected. Where I'm running into problems is with special characters, particularly with German, Swedish, and Spanish municipalities, which all have at least one or two with special characters.
The AJAX application is called, and the server responds with the following XML.
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<response>
<lang>de</lang>
<state id='0'>Please select a state or province</state>
<state id='79'>Niedersachsen</state>
<state id='80'>Baden-W?rttemberg</state>
<state id='81'>Bayern</state>
<state id='82'>Berlin</state>
<state id='83'>Brandenburg</state>
<state id='84'>Bremen</state>
<state id='85'>Hamburg</state>
<state id='86'>Hessen</state>
<state id='87'>Mecklenburg-Vorpommern</state>
<state id='88'>Nordrhein-Westfalen</state>
<state id='89'>Rheinland-Pfalz</state>
<state id='90'>Saarland</state>
<state id='91'>Sachsen</state>
<state id='92'>Sachsen-Anhalt</state>
<state id='93'>Schleswig-Holstein</state>
<state id='94'>Th?ringen</state>
</response>
I've tried switching out the special characters with entities, such as ü, though this doesn't work. I've also tried setting the lang attribute, but that doesn't work either.
I'm using a <select> box, when the response is received the following function parses through the XML, truncates, and then populates the <select> box.
Code:
function process_states()
{
debug(http.responseText, 'register-debug');
if (document.getElementById('register-state'))
{
var state = document.getElementById('register-state');
var _lang = root.getElementsByTagName('lang')[0].firstChild.data;
state.lang = _lang;
// truncate the options
state.length = 0;
var states = root.getElementsByTagName('state');
for (var i = 0; i < states.length; i++)
{
state.options[i] = new Option(states[i].firstChild.data, states[i].getAttribute('id'));
state.options[i].lang = _lang;
}
//document.getElementById('register-state').innerHTML = http.responseText;
if (state.length == 1)
{
alert('Aye! Cucaracha!');
}
}
}
The document that this is going into is XHTML 1.0 strict, servered as text/html with no XML declaration.
I'm using a <meta> tag to specify a UTF-8 character set.
Code:
<meta http-equiv='content-type' content='text/html; charset=utf-8' />
Explorer chokes hard on the special characters, and throws JavaScript errors due to their existence. Firefox just displays question marks.
This seems to be a character set issue. Any ideas on how I can internationalize gracefully?
Regards,
Rich
--
[
http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design