Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-08-2012, 09:01 PM   PM User | #1
jason_kelly
Regular Coder

 
Join Date: Sep 2011
Posts: 140
Thanks: 88
Thanked 0 Times in 0 Posts
jason_kelly is an unknown quantity at this point
ASCII Question

Hello,

I have the following text string, however, when I write it to texbox,

The ›› 's appears as two square boxes, (btw it is ASCII # 155.)

How can I fix this?


str_txt = "›› A NOTIFICATION HAS BEEN SENT TO"

document.getElementById('box1').value = str_txt

Many and much thanks for everyones help.
jason_kelly is offline   Reply With Quote
Old 03-08-2012, 09:03 PM   PM User | #2
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,764
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
Try ...
Code:
str_txt = "\›\› A NOTIFICATION HAS BEEN SENT TO"
jmrker is offline   Reply With Quote
Users who have thanked jmrker for this post:
jason_kelly (03-09-2012)
Old 03-08-2012, 09:32 PM   PM User | #3
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,462
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
try:

">> A NOTIFICATION HAS BEEN SENT TO"
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Users who have thanked rnd me for this post:
jason_kelly (03-09-2012)
Old 03-09-2012, 01:18 AM   PM User | #4
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,455
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
To use ASCII codes in JavaScript specify \x99 where 99 is the hexadecimal value of the ASCII character. 153 decimal actually is 99 hex and so you would use:

str_txt = "\x99 A NOTIFICATION HAS BEEN SENT TO"

Of course since the code is over 127 you need to ensure that the page is using the correct charset. You might do better to use the unicode value for the character which can be specified as \u9999 where the again the 9999 is the hexadecimal value (I am not sure what character value it would be in unicode - you'd have to look it up).
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/

Last edited by felgall; 03-09-2012 at 02:07 AM..
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
jason_kelly (03-09-2012)
Old 03-09-2012, 01:45 AM   PM User | #5
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,764
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
Thumbs up

Looks like post #2 and #3 are equivalent:
Code:
<html>
<head>
<title> Untitled </title>
<script type="text/javascript">
str_txt1 = "\›\› A NOTIFICATION HAS BEEN SENT TO";
str_txt2 = "›› A NOTIFICATION HAS BEEN SENT TO";
window.onload = function() {
  document.getElementById('txt1info').value = str_txt1;
  document.getElementById('txt2info').value = str_txt2;
}
</script>
</head>
<body>
<input type="text" id="txt1info" value="" size="40"><br>
<input type="text" id="txt2info" value="" size="40">
</body>
</html>
jmrker is offline   Reply With Quote
Users who have thanked jmrker for this post:
jason_kelly (03-09-2012)
Old 03-09-2012, 01:51 AM   PM User | #6
webdev1958
Banned

 
Join Date: Apr 2011
Posts: 656
Thanks: 14
Thanked 69 Times in 69 Posts
webdev1958 can only hope to improve
Quote:
Originally Posted by jmrker View Post
Looks like post #2 and #3 are equivalent:
Your code as posted displays jibberish in my IE9 for the chars at the start. They display correctly only when I add an appropriate character set in the <head>
webdev1958 is offline   Reply With Quote
Users who have thanked webdev1958 for this post:
jason_kelly (03-09-2012)
Old 03-09-2012, 02:01 AM   PM User | #7
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,455
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by webdev1958 View Post
Your code as posted displays jibberish in my IE9 for the chars at the start. They display correctly only when I add an appropriate character set in the <head>
I agree. That's exactly the problem that the OP is having and why neither of those posts will solve the problem.

Using the \x99 format might work but will possibly still be dependent on the encoding. The only way really guaranteed to work is to use \u9999 (substituting the appropriate hexadecimal unicode value for the 9999).

The value to use is \u00obb - that is the unicode value for the symbol in the string. So the line simply needs to read:

str_txt = "\u00bb A NOTIFICATION HAS BEEN SENT TO"
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/

Last edited by felgall; 03-09-2012 at 02:08 AM.. Reason: looked up correct code
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
jason_kelly (03-09-2012)
Old 03-09-2012, 02:13 AM   PM User | #8
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,764
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
Exclamation

Quote:
Originally Posted by webdev1958 View Post
Your code as posted displays jibberish in my IE9 for the chars at the start. They display correctly only when I add an appropriate character set in the <head>
Quote:
Originally Posted by felgall View Post
I agree. That's exactly the problem that the OP is having and why neither of those posts will solve the problem.

Using the \x99 format might work but will possibly still be dependent on the encoding. The only way really guaranteed to work is to use \u9999 (substituting the appropriate hexadecimal unicode value for the 9999).

The value to use is \u00obb - that is the unicode value for the symbol in the string. So the line simply needs to read:

str_txt = "\u00bb A NOTIFICATION HAS BEEN SENT TO"
Well if MSIE made a compatible browser that played well with others, it might not be a problem.
I avoid MSIE whenever possible, so I guess I start my postings from now on with the caveat of: "Tested in FF or Chrome only"!
jmrker is offline   Reply With Quote
Users who have thanked jmrker for this post:
jason_kelly (03-09-2012)
Old 03-09-2012, 02:20 AM   PM User | #9
webdev1958
Banned

 
Join Date: Apr 2011
Posts: 656
Thanks: 14
Thanked 69 Times in 69 Posts
webdev1958 can only hope to improve
[ot]

Quote:
Originally Posted by jmrker View Post
Well if MSIE made a compatible browser that played well with others, it might not be a problem.
Personally I have no issue with IE but I understand why many people do, but that's a whole new can of bees wax .

But suffice to say, if building websites for the www, then regardless of what one might think of IE, there will be a very significant number of IE users for a quite a few years yet and so IE should be included in browser testing for websites.

I normally use these browser stats as a guide.

[/ot]

Last edited by webdev1958; 03-09-2012 at 02:23 AM..
webdev1958 is offline   Reply With Quote
Users who have thanked webdev1958 for this post:
jason_kelly (03-09-2012)
Old 03-09-2012, 02:24 AM   PM User | #10
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,462
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by jmrker View Post
Looks like post #2 and #3 are equivalent:

no i used ">" or [SHIFT]+[.] ( &gt; ) to make mine, no encoding or escaping needed.

if they look the same, well thanks, i thought so to.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%

Last edited by rnd me; 03-09-2012 at 02:30 AM..
rnd me is offline   Reply With Quote
Users who have thanked rnd me for this post:
jason_kelly (03-09-2012)
Old 03-09-2012, 02:29 AM   PM User | #11
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,462
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by jmrker View Post
Well if MSIE made a compatible browser that played well with others, it might not be a problem.
they have made two of them now. the slash escaping you showed was a quirk in the other browsers, not a standard. do you want it standard or to play well with others? ie10 supports more standards than opera 12.

I hate IE, but I don't consider 9 and 10 to be IE.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Users who have thanked rnd me for this post:
jason_kelly (03-09-2012)
Old 03-09-2012, 08:15 AM   PM User | #12
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,455
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by rnd me View Post
no i used ">" or [SHIFT]+[.] ( &gt; ) to make mine, no encoding or escaping needed.

if they look the same, well thanks, i thought so to.
Well that is using a totally different character - in fact you used two characters in place of the one that the OP was trying to use.

There are several characters that look like that > is the biggest of them, then there is one similar but about half the size and finally the one that looks like what tho OP wanted that has two of those smaller marks in the one character - the one with unicode \u00bb - which all browsers should be able to handle correctly.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
jason_kelly (03-09-2012)
Old 03-09-2012, 01:39 PM   PM User | #13
jason_kelly
Regular Coder

 
Join Date: Sep 2011
Posts: 140
Thanks: 88
Thanked 0 Times in 0 Posts
jason_kelly is an unknown quantity at this point
A huge thanks to everyone for their wonderful help on this one.

Seems the culprit was a declaration in the <HEAD> element.

All seemed to work fine when the following was applied:

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

Cheers and many and much thanks again.

J
jason_kelly is offline   Reply With Quote
Old 03-12-2012, 03:55 PM   PM User | #14
jalarie
Regular Coder

 
Join Date: Jun 2002
Location: Flint, Michigan, USA
Posts: 593
Thanks: 1
Thanked 19 Times in 19 Posts
jalarie is an unknown quantity at this point
Instead of 155, use 187.
__________________
Visit my site at http://spruce.flint.umich.edu/~jalarie/.
jalarie is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:11 AM.


Advertisement
Log in to turn off these ads.