Friday, March 2, 2012

[JavaScript] Display Symbols in Alert

Alerts are what we usually use to prompt users about something. And sometimes we need to prompt something like an email address. We all know that email address have the @ symbol. Most likely will just add the @ symbol but once checking your work, the alert box is empty or maybe some codes will show on the page.

The problem here is symbols won't show in alert boxes. The solution? you need to type its unicode value instead of the symbol itself.

So for @ symbol, its unicode value is \u0040.

For example, instead of...
alert('contact us at customer@service.com');

The code must be like this...
alert('contact us at customer\u0040service.com');

Note that not only symbols have unicode values, other characters also have such as letters.

To convert characters to unicode, click here.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...