Forum Moderators: open
I use a javascript alertbox to display user feedback on a language learning site.
The strings are retrieved from a MySQL database. Some special characters are stored as html in the database:
wǒ tàitai
These strings are displayed correctly on the web page (the ǒ is an o with a diacritic curl above), but when shown in the alertbox the string is shown as literally "wǒ tàitai"
Is there any way to display the special characters correctly, i.e. to make the alertbox interpret the string in the same way as the web page?
The alertbox code currently used is this one:
+++++++++++++++++
<script type="application/x-javascript" language="JavaScript">
<!--
arComMist = new Array()
<%
for i=0 to UBound(arJscript)
if arJscript(i,0) > 0 then
Response.write "arComMist["&arJscript(i,0)&"] = new Array(2);" & VBCrLf
Response.write "arComMist["&arJscript(i,0)&"][0] = '"&arJscript(i,1)&"';" & VBCrLf
Response.write "arComMist["&arJscript(i,0)&"][1] = '"&arJscript(i,2)&"';" & VBCrLf
End if
Next
%>
function alertBox(iComMistId) {
alert(arComMist[iComMistId][0]+"\n\nRätt svar är: "+arComMist[iComMistId][1]);
}
// -->
</script>
++++++++++++++++++++++++++++++++
Greatful for any heelp on this,
Jakob H.
[edited by: eelixduppy at 3:35 am (utc) on Feb. 25, 2009]
The simplest approach might be to create a floating div which simulates an alert, since then the full rendering capabilities would be applied to the div content.
<script type="application/x-javascript" language="JavaScript">
<!--
arComMist = new Array()
arComMist[8] = new Array(2);
arComMist[8][0] = 'det är fel!';
arComMist[8][1] = 'wǒ tàitai';
function alertBox(iComMistId) {
alert(arComMist[iComMistId][0]+"\n\nRätt svar är: "+arComMist[iComMistId][1]);
}
// -->
</script>
(It´s the "'wǒ tàitai';" that needs to be interpreted as html. Could this not be handled with quotes etc.?)
What is a floating div? How would that code look?
Many thanks again,
Jakob H.
When I say "floating div", (not to be confused with a div that has a CSS positioning property of "float"), I simply mean a div absolutely positioned over the page. The following illustrates creating the div on the fly. Perhaps an easier approach is to create the div in the HTML markup and assign it display:none. You can then make it visible when you need it. Obviously, more styling would be necessary to simulate an alert box.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css">
</style>
<script type="text/javascript">
function floatDiv(){
var new_div=document.createElement("div");
new_div.style.position="absolute";
new_div.style.top="200px";
new_div.style.left="200px";
new_div.style.height="300px";
new_div.style.width="400px";
new_div.style.backgroundColor="#ddbbaa";
new_div.id="alert_div";
document.getElementById("pg_bod").appendChild(new_div);
var new_txt=document.createTextNode("your alert message");
document.getElementById("alert_div").appendChild(new_txt);
}
</script>
</head>
<body id="pg_bod">
<p>
<a href="#" onclick="floatDiv();">test</a>
</p>
</body>
</html>