Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

display spanish accents in javascript alert  RSS feed

 
kalpana gali
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am having trouble displaying an alert message in Spanish in my JSP. the local and everything is getting picked up currently but the spanish accents are not getting converted. Here is an example of what I am trying to do. I want to display the message "Email is required" in spanish using a window.alert() method.

so when i code it like


<script language="javascript" type="text/javascript" >
function showMsg()
{
window.alert('Direcci& #243;n de correo electr& #243;nico obligatorio.' + '\n');
}
</script>

<a href="javascript:alert('Direcci& #243;n de correo electr& #243;nico obligatorio.' + '\n');" > test1 </a>
<br>
<br>
<a href="javascript:showMsg();">test2</a>


the first link "test1" works fine. but the second link "test2" does not translate the '& #243;' to the corresponding accent but displays it as it is.

I added a space after the '&' symbol for the purpose of this post as the accent was getting translated.

Can anyone help me with this.Thanks in advance

[ June 30, 2008: Message edited by: ramana neelam ]
[ June 30, 2008: Message edited by: ramana neelam ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"raneelam",
Please check your private messages regarding an important administrative matter.
-Ben
 
Matteo Di Furia
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems HTML entities are somehow not converted. You can use this code :



The key is the function html_entity_decode which actually seems to make html entities to be converted by browser rendering engine, rather than from the JavaScript engine.

Note : this snippet is not mine, I found it here : http://javascript.internet.com/snippets/convert-html-entities.html#
(just to not get credit for it)

[ July 01, 2008: Message edited by: Matteo Di Furia ]
[ July 01, 2008: Message edited by: Matteo Di Furia ]
 
kalpana gali
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Matteo, will try it this way.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!