472,336 Members | 1,306 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,336 software developers and data experts.

Foreign characters in javascript alerts

21
I must use alerts in French with accented characters and what I get is gibberish.

How can I display alert messages properly, as HTML character codes for accented characters don't work in javascript alerts?

The scripts are stored in a .js file and I am referencing it from HTML. The HTML document is 4.01 Transitional and the language is UTF-8.

Any help is greatly appreciated.
Mar 6 '08 #1
17 9773
acoder
16,027 Expert Mod 8TB
Can you give some examples of codes that don't work.
Mar 7 '08 #2
hsriat
1,654 Expert 1GB
I must use alerts in French with accented characters and what I get is gibberish.

How can I display alert messages properly, as HTML character codes for accented characters don't work in javascript alerts?

The scripts are stored in a .js file and I am referencing it from HTML. The HTML document is 4.01 Transitional and the language is UTF-8.

Any help is greatly appreciated.
Instead of writing the message in French, write the Unicode for each character.
You may find the Unicode characters here.

eg, for alert('ABC');
use alert('\u0041\u0042\u0043');
Mar 7 '08 #3
ineuw
21
I apologize but some emergencies prevented me from responding. Thank you both for the replies. The characters in question are with accents or circumflex like é (ANSI 02333) or ô (ANSI 0244) etc.

Inputting as alert("Veuillez indiquer le nom de societé!") where the alert contains the actual character generates an HTML error when opening the web page.

Inputting as alert("Veuillez indiquer le nom de societ\0xE9!") using the hex value for the é character, preceded by the escape code, displays a box.

Your additional comments would be greatly appreciated.
Mar 12 '08 #4
acoder
16,027 Expert Mod 8TB
I have no such problems with the example you have given.

What's the error message?
Mar 12 '08 #5
ineuw
21
When I open the web page, the error is on line 12. 'Unterminated string constant'. Line 12 is: <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

When I click on "Submit", the error is 'Object expected.

I changed the charset to ISO-8859-1 and this seems to work for the error message in the external javascript, but then text in the body of the HTML document comes up as gibberish as in:

'Les données sont acceptées dans n’importe quel format.' The gibberish is the single quote ['] as in [n'importe]

I also tested the web page with Tidy, and it is error free - (HTML 4.01 Transitional DTD)
Mar 13 '08 #6
hsriat
1,654 Expert 1GB
When I open the web page, the error is on line 12. 'Unterminated string constant'. Line 12 is: <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

When I click on "Submit", the error is 'Object expected.

I changed the charset to ISO-8859-1 and this seems to work for the error message in the external javascript, but then text in the body of the HTML document comes up as gibberish as in:

'Les données sont acceptées dans n’importe quel format.' The gibberish is the single quote ['] as in [n'importe]

I also tested the web page with Tidy, and it is error free - (HTML 4.01 Transitional DTD)
Meta tag would not give such errors, it must be something in the server side script. Check your quotes. Character set should be UTF-8 only, as you are using Unicode characters.

Post the HTML part of you code (view source part).
Mar 13 '08 #7
acoder
16,027 Expert Mod 8TB
When I open the web page, the error is on line 12. 'Unterminated string constant'. Line 12 is: <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

When I click on "Submit", the error is 'Object expected.
Check the error console of a decent browser. It should show you the line (in the code) which causes the error. It'll be line 12 in the JavaScript.
Mar 13 '08 #8
ineuw
21
Thanks to all for the input. I use IE6 for testing because it is still the most prolific browser. I also test the pages with Firefox 2+, Opera 9+ and Safari. The problem is with IE6. Below is the HTML with the javascript for form validation containing the "é" character (Hex 0xE9)(ANSI 0233). IE6 causes an error where the other browsers don't but still don't display the character properly. Just click on Submit, or the Reset buttons.
================================================== ===============

[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/transitional.dtd">
<html>
<head>
<title>Test</title>
<meta name="generator" content="HTML Tidy for Windows (vers 6 November 2007), see www.w3.org">
<meta name="generator" content="Textpad version 5.0.3 - http://www.textpad.com">
<meta name="robots" content="noindex, noarchive">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="refresh" content="650">

<!-- start form validator -->
<script type="text/javascript" src="Test.js"></script>
</head>
<body>

<table class="main" width="650" id="policy" align="center" summary="policy">
<tr>
<td class="grey" align="center" colspan="2"></td>
</tr>
<tr>
<td>
<table border="0" cellpadding="10" cellspacing="20" align="center" summary="external links">
</table>
</td>
</tr>
</table>

<br>

<form name="Test_form" method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="form_username" value="">
<input type="hidden" name="source_document" value="Gestion des donnees d'adresse">

<br>

<table class="main" width="650" align="center" id="quote_request" summary="quote_request">
<tr>
<td>Soci&eacute;t&eacute;</td>
<td><input class="flat" type="text" name="company" id="company" value="" size="70" maxlength="70"></td>
</tr>
<tr>
<td>Courriel</td>
<td><input class="flat" type="text" name="email_address" id="email_address" value="" size="70" maxlength="70">
</td>
</tr>
<tr>
<td>Attachez le fichier<br>de donn&eacute;es</td>
<td><input class="flat" type="file" name="myform_file" size="70" maxlength="100" id="form_file"></td>
</tr>
<tr>
<td>Quantit&eacute;<br>approximative</td>
<td><input class="flat" type="text" name="quantity" id="quantity" value="0" size="10" maxlength="10"></td>
</tr>
<tr>
<td>Requis par</td>
<td><input class="flat" type="text" name="requiredby" id="requiredby" value="" size="25" maxlength="25"></td>
</tr>
</table>
<br>
<table align="center" id="submit_reset" summary="submit_reset">
<tr>
<td align="center"><input type="reset" id="reset" value="Effacer" onclick="advanced_selected(this.form)"></td>
<td align="center"><input type="submit" id="submit" value="Soumettez la demande" onclick="return check_form_fields(this.form)"></td>
</tr>
</table>
</form>
<br>
<br>
<br>
</body>
</html>[/HTML]
================================================== ===============
Test.js
================================================== ===============
Expand|Select|Wrap|Line Numbers
  1. function check_form_fields(form)
  2. {
  3. var ValidChars = "0123456789";
  4. var IsNumber = true;
  5. var Char;
  6. var i;
  7. var today = new Date();
  8. if (form.company.value == "")
  9. {
  10. alert("Veuillez indiquer le nom de societé!");
  11. form.company.focus();
  12. return false;
  13. }
  14. if (form.email_address.value == "")
  15. {
  16. alert("Veuillez indiquer votre adresse courriel!");
  17. form.company.focus();
  18. return false;
  19. }
  20. if(form.quantity.value < "1")
  21. {
  22. alert("Veuillez indiquer la quantite approximative!");
  23. form.quantity.focus();
  24. return false;
  25. }
  26. for (i = 0; i < form.quantity.value.length && IsNumber == true; i++)
  27. {
  28. Char = form.quantity.value.charAt(i);
  29. if (ValidChars.indexOf(Char) == -1)
  30. {
  31. IsNumber = false;
  32. alert("Veuillez indiquer la quantite approximative!");
  33. form.quantity.focus();
  34. return false;
  35. }
  36. }
  37. if (form.requiredby.value == "" || form.requiredby.value == "None")
  38. {
  39. alert("Veuillez indiquer la date requise!");
  40. form.requiredby.focus();
  41. return false;
  42. }
  43. var dt_input = form.requiredby.value;
  44. var input_year = dt_input.substring(0,4);
  45. var input_month = dt_input.substring(5,7)-1;
  46. var input_day = dt_input.substring(8,10);
  47. var date_input = new Date(input_year, input_month, input_day);
  48. date_input.setHours(23);
  49. if (date_input < today )
  50. {
  51. alert("La date ne peut pas etre plus tot qu'aujourd'hui!");
  52. form.requiredby.focus();
  53. form.requiredby.value = "";
  54. return false;
  55. }
  56. return true;
  57. }
Mar 13 '08 #9
acoder
16,027 Expert Mod 8TB
It should work with ISO-8859-1:
Expand|Select|Wrap|Line Numbers
  1. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
PS. please use [code] tags when posting code.
Mar 14 '08 #10
ineuw
21
It should work with ISO-8859-1:
Expand|Select|Wrap|Line Numbers
  1. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
PS. please use [code] tags when posting code.
Sorry about the lack of [code] tags. If I change the charset to ISO-8859-1, this eliminates the error of the javascript but introduces another problem in the body od the web page, as follows:

The ’ symbol replaces the single quote "n'importe" becomes n’importe.

Les données sont acceptées dans n’importe quel format. Nous vous demandons que les fichiers de données nous soient envoyés comprimés, en se servant de n’importe quel logiciel de compression.

So, I am stuck no matter which direction I take

ty..
Mar 14 '08 #11
acoder
16,027 Expert Mod 8TB
If I change the charset to ISO-8859-1, this eliminates the error of the javascript but introduces another problem in the body od the web page, as follows:

The ’ symbol replaces the single quote "n'importe" becomes n’importe.

Les données sont acceptées dans n’importe quel format. Nous vous demandons que les fichiers de données nous soient envoyés comprimés, en se servant de n’importe quel logiciel de compression.
I don't see this problem. The sentence appears fine. You didn't have this in the code you posted earlier.
Mar 16 '08 #12
ineuw
21
I don't see this problem. The sentence appears fine. You didn't have this in the code you posted earlier.

UTF-8 = Les données sont acceptées dans n’importe quel format
ISO-8859-1 = Les données sont acceptées dans n’importe quel format.

When this is displayed in any browser and the charset is ISO-8859-1 then, the single quotes change to these symbols.
Mar 16 '08 #13
acoder
16,027 Expert Mod 8TB
Again tested on IE6 + Firefox with no problems. Is this the normal single quote or another character?

Can you show a test page or your updated code that demonstrates this problem.
Mar 17 '08 #14
ineuw
21
Again tested on IE6 + Firefox with no problems. Is this the normal single quote or another character?
Can you show a test page or your updated code that demonstrates this problem.
Expand|Select|Wrap|Line Numbers
  1. <div>6 colonnes ou moins de données d’adresses afin de satisfaire les exigences</div>
  2.  
The above line is part of a simple French sentence which exists in the actual HTML document. I removed all non-essential portions of the previously posted code so as not to confuse the issue.

Please paste code this into anywhere in the previously posted code to see the results.

When using iso-8859-1 as the charset, the javascript alerts are corrected but, the French characters in the HTML body turn into symbols as shown here:

"6 colonnes ou moins de données d’adresses afin de satisfaire les exigences"
Mar 18 '08 #15
acoder
16,027 Expert Mod 8TB
The following code worked fine:
[html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/transitional.dtd">
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function check_form_fields(form)
{
var ValidChars = "0123456789";
var IsNumber = true;
var Char;
var i;
var today = new Date();
if (form.company.value == "")
{
alert("Veuillez indiquer le nom de societé!");
form.company.focus();
return false;
}
if (form.email_address.value == "")
{
alert("Veuillez indiquer votre adresse courriel!");
form.company.focus();
return false;
}
if(form.quantity.value < "1")
{
alert("Veuillez indiquer la quantite approximative!");
form.quantity.focus();
return false;
}
for (i = 0; i < form.quantity.value.length && IsNumber == true; i++)
{
Char = form.quantity.value.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsNumber = false;
alert("Veuillez indiquer la quantite approximative!");
form.quantity.focus();
return false;
}
}
if (form.requiredby.value == "" || form.requiredby.value == "None")
{
alert("Veuillez indiquer la date requise!");
form.requiredby.focus();
return false;
}
var dt_input = form.requiredby.value;
var input_year = dt_input.substring(0,4);
var input_month = dt_input.substring(5,7)-1;
var input_day = dt_input.substring(8,10);
var date_input = new Date(input_year, input_month, input_day);
date_input.setHours(23);
if (date_input < today )
{
alert("La date ne peut pas etre plus tot qu'aujourd'hui!");
form.requiredby.focus();
form.requiredby.value = "";
return false;
}
return true;
}</script>
</head>
<body>

<table class="main" width="650" id="policy" align="center" summary="policy">
<tr>
<td class="grey" align="center" colspan="2"></td>
</tr>
<tr>
<td>
<table border="0" cellpadding="10" cellspacing="20" align="center" summary="external links">
</table>
</td>
</tr>
</table>

<br>

<form name="Test_form" method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="form_username" value="">
<input type="hidden" name="source_document" value="Gestion des donnees d'adresse">

<br>

<table class="main" width="650" align="center" id="quote_request" summary="quote_request">
<tr>
<td>Soci&eacute;t&eacute;</td>
<td><input class="flat" type="text" name="company" id="company" value="" size="70" maxlength="70"></td>
</tr>
<tr>
<td>Courriel</td>
<td><input class="flat" type="text" name="email_address" id="email_address" value="" size="70" maxlength="70">
</td>
</tr>
<tr>
<td>Attachez le fichier<br>de donn&eacute;es</td>
<td><input class="flat" type="file" name="myform_file" size="70" maxlength="100" id="form_file"></td>
</tr>
<tr>
<td>Quantit&eacute;<br>approximative</td>
<td><input class="flat" type="text" name="quantity" id="quantity" value="0" size="10" maxlength="10"></td>
</tr>
<tr>
<td>Requis par</td>
<td><input class="flat" type="text" name="requiredby" id="requiredby" value="" size="25" maxlength="25"></td>
</tr>
</table>
<br>
Les données sont acceptées dans n’importe quel format
<table align="center" id="submit_reset" summary="submit_reset">
<tr>
<td align="center"><input type="reset" id="reset" value="Effacer" onclick="advanced_selected(this.form)"></td>
<td align="center"><input type="submit" id="submit" value="Soumettez la demande" onclick="return check_form_fields(this.form)"></td>
</tr>
</table>
<div>6 colonnes ou moins de données d’adresses afin de satisfaire les exigences</div>
</form>
</body>
</html>[/html]
Mar 18 '08 #16
ineuw
21
Hi acoder, I finally found the problem, which is Textpad the text editor. Some of the documents were encoded as utf-8, and some were ANSI. Changing everything to ANSI, including the .javascript files, resolved the problem.

Do you know of any command line utility that can make the encoding changes through a script or a batch file? :-D

Many thanks again for all your time.
Mar 18 '08 #17
acoder
16,027 Expert Mod 8TB
Hi acoder, I finally found the problem, which is Textpad the text editor. Some of the documents were encoded as utf-8, and some were ANSI. Changing everything to ANSI, including the .javascript files, resolved the problem.
Heh, I use Notepad++ or even Notepad for something quick.

Do you know of any command line utility that can make the encoding changes through a script or a batch file? :-D
Try asking in the Misc. forum.

Many thanks again for all your time.
You're welcome again.
Mar 19 '08 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Hugo Fjelsted Alrøe | last post by:
I am fairly new at MySQL, so please excuse any ignorance. We are using MySQL (version 3.23.48) in connection with an Eprints = archive. We have...
8
by: Daniel | last post by:
I'm trying to make a site work for japanese characters. It works fine except for the alerts in javascript. The characters are stored in unicode,...
12
by: Smash | last post by:
i have this function: ------------------------------------------------------------ function isAlfaNumeric(vnos,space) { if (space==false) {...
14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was...
7
by: swethasivaram | last post by:
Hello I have a Java-based web application whose interface can be in multiple languages. My requirement is that the javascript alerts that I...
6
by: Melissa | last post by:
Initially the form is loaded using ASP and HTML and the ü codes display the characters correctly. I have the values stored in a javascript array...
5
by: cbs7 | last post by:
Hi all I'm a complete newbie to web development and Javascript especially. I've been creating a form for a webpage and have used a validation...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the...
3
by: tshad | last post by:
Using asp.net 2.0, I am finding that at times, the old javascript will still be there. I was working with it for a couple of hours and the...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.