Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14

Thread: ASCII Question

  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    182
    Thanks
    139
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,073
    Thanks
    38
    Thanked 498 Times in 492 Posts
    Try ...
    Code:
    str_txt = "\›\› A NOTIFICATION HAS BEEN SENT TO"

  • Users who have thanked jmrker for this post:

    jason_kelly (03-09-2012)

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,293
    Thanks
    10
    Thanked 583 Times in 564 Posts
    try:

    ">> A NOTIFICATION HAS BEEN SENT TO"
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • Users who have thanked rnd me for this post:

    jason_kelly (03-09-2012)

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,611
    Thanks
    0
    Thanked 645 Times in 635 Posts
    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).
    Last edited by felgall; 03-09-2012 at 02:07 AM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    jason_kelly (03-09-2012)

  • #5
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,073
    Thanks
    38
    Thanked 498 Times in 492 Posts

    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>

  • Users who have thanked jmrker for this post:

    jason_kelly (03-09-2012)

  • #6
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    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>

  • Users who have thanked webdev1958 for this post:

    jason_kelly (03-09-2012)

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,611
    Thanks
    0
    Thanked 645 Times in 635 Posts
    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"
    Last edited by felgall; 03-09-2012 at 02:08 AM. Reason: looked up correct code
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    jason_kelly (03-09-2012)

  • #8
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,073
    Thanks
    38
    Thanked 498 Times in 492 Posts

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

  • Users who have thanked jmrker for this post:

    jason_kelly (03-09-2012)

  • #9
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    [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.

  • Users who have thanked webdev1958 for this post:

    jason_kelly (03-09-2012)

  • #10
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,293
    Thanks
    10
    Thanked 583 Times in 564 Posts
    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.
    Last edited by rnd me; 03-09-2012 at 02:30 AM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • Users who have thanked rnd me for this post:

    jason_kelly (03-09-2012)

  • #11
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,293
    Thanks
    10
    Thanked 583 Times in 564 Posts
    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 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • Users who have thanked rnd me for this post:

    jason_kelly (03-09-2012)

  • #12
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,611
    Thanks
    0
    Thanked 645 Times in 635 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    jason_kelly (03-09-2012)

  • #13
    Regular Coder
    Join Date
    Sep 2011
    Posts
    182
    Thanks
    139
    Thanked 0 Times in 0 Posts
    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

  • #14
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    620
    Thanks
    1
    Thanked 20 Times in 20 Posts
    Instead of 155, use 187.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •