...

View Full Version : ASCII Question



jason_kelly
03-08-2012, 09:01 PM
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.

jmrker
03-08-2012, 09:03 PM
Try ...


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

rnd me
03-08-2012, 09:32 PM
try:

">> A NOTIFICATION HAS BEEN SENT TO"

felgall
03-09-2012, 01:18 AM
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).

jmrker
03-09-2012, 01:45 AM
Looks like post #2 and #3 are equivalent: :thumbsup:


<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>

webdev1958
03-09-2012, 01:51 AM
Looks like post #2 and #3 are equivalent: :thumbsup:


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>

felgall
03-09-2012, 02:01 AM
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"

jmrker
03-09-2012, 02:13 AM
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"

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"!

webdev1958
03-09-2012, 02:20 AM
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 :cool:.

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 (http://marketshare.hitslink.com/browser-market-share.aspx?qprid=0&qpcustomd=0) as a guide.

rnd me
03-09-2012, 02:24 AM
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.

rnd me
03-09-2012, 02:29 AM
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.

felgall
03-09-2012, 08:15 AM
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.

jason_kelly
03-09-2012, 01:39 PM
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

jalarie
03-12-2012, 03:55 PM
Instead of 155, use 187.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum