473,847 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Foreign characters in javascript alerts

21 New Member
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 10108
acoder
16,027 Recognized Expert Moderator MVP
Can you give some examples of codes that don't work.
Mar 7 '08 #2
hsriat
1,654 Recognized Expert Top Contributor
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\u 0042\u0043');
Mar 7 '08 #3
ineuw
21 New Member
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 Recognized Expert Moderator MVP
I have no such problems with the example you have given.

What's the error message?
Mar 12 '08 #5
ineuw
21 New Member
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 Recognized Expert Top Contributor
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 Recognized Expert Moderator MVP
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 New Member
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.dt d">
<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="Textpa d version 5.0.3 - http://www.textpad.com ">
<meta name="robots" content="noinde x, 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="extern al links">
</table>
</td>
</tr>
</table>

<br>

<form name="Test_form " method="post" action="" enctype="multip art/form-data">
<input type="hidden" name="form_user name" value="">
<input type="hidden" name="source_do cument" value="Gestion des donnees d'adresse">

<br>

<table class="main" width="650" align="center" id="quote_reque st" 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_add ress" id="email_addre ss" 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_fi le" size="70" maxlength="100" id="form_file"> </td>
</tr>
<tr>
<td>Quantit&eac ute;<br>approxi mative</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="requiredb y" id="requiredby " value="" size="25" maxlength="25"> </td>
</tr>
</table>
<br>
<table align="center" id="submit_rese t" summary="submit _reset">
<tr>
<td align="center"> <input type="reset" id="reset" value="Effacer" onclick="advanc ed_selected(thi s.form)"></td>
<td align="center"> <input type="submit" id="submit" value="Soumette z la demande" onclick="return check_form_fiel ds(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 Recognized Expert Moderator MVP
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

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

Similar topics

0
2168
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 non-english deposits in the archive, and non-standard = characters are not always shown right in our system. They are shown = wrong in the subscription alerts that the archive generates and sends = out - this is what annoys us. And they are shown wrong in the database = itself. But they are shown...
8
10531
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, as this; 'コミック全巻配' Those unicode characters are translated by the browser, but not in the alert.
12
11455
by: Smash | last post by:
i have this function: ------------------------------------------------------------ function isAlfaNumeric(vnos,space) { if (space==false) { validRegExp = /^{0,}$/; } else { validRegExp = /^{0,}$/; }
14
5505
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 originally created from a program I found on the net that works well as an html page. It brings up a modal popup window that I have been trying to work out for days now and this was the closest I have been able to come. I added a little asp.net code and an asp.net button and cannot get it to
7
8372
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 display should be displayed in the language in which the interface has been generated. The interface language is dynamically loaded and the text is displayed using Java's <fmttags. How can I make the Javascript alerts, etc. also change their display language dynamically? Is it possible in...
6
3858
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 so that I can more easily and dynamically change the state/region dropdown when the country changes. However, when my javascript code tries to add the new option and print out new region the literal value such as "Würrtemberg" is displayed instead of the special character. Can this be done in...
5
19084
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 script gen_validatorv2.js which I downloaded from the zip file referenced on http://www.javascript-coder.com/html-form/javascript-form-validation.phtml I managed to get everything working and was testing through Firefox that alerts were generated. However at the very end I thought I'd better check...
1
25711
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 kind that doesn't help kill the germs that cause bad breath)? Scope describes the context in which a variable can be used. For example, if a variable's scope is a certain function, then that variable can only be used in that function. If you were to try to access that variable anywhere else in...
3
3433
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 changes seem to happen. But at the end of the day, I found that my last changes weren't taking affect. I was trying to delete my "alerts" before doing a final build but even after taking out all my alerts, when I built it and ran it - the alerts were still
0
9882
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9727
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10645
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10706
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10335
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9481
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7880
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4116
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.