#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Ottawa, Ontario
    Posts
    50
    Rep Power
    13

    Lightbulb Bad JavaScript bug with special characters


    Hi,

    As I found that JavaScript is not capable to render numbered entities for special characters in any DHTML code. So, all codes like &_#_245_; ('õ' without uderscores) are displayed as numbers when used in form elements.

    Simple example:

    var test = "ó";
    alert(test); - shows code
    document.write(test); - shows character

    Does anyone know a way to render character code as a character in alert() function or form elements?

    Thanks,
    Vic
  2. #2
  3. No Profile Picture
    Beelzebub
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    The nether regions...ok, San Diego
    Posts
    164
    Rep Power
    13
    Yeah, that kind of stuff can be confusing. The alert box uses escape codes, and the write method uses html character entities. Try alert(unescape(test))

    Sorry...I didn't test that enough. I'll keep trying.
    Last edited by evildj; August 26th, 2001 at 04:21 PM.
  4. #3
  5. No Profile Picture
    Seņor Member
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2000
    Posts
    1,157
    Rep Power
    37
    Are you sure it's not just that the font/typeface used in form elements is one that doesn't have what you are expecting for that ASCII equivalent? Try setting your typeface in the rest of your page to Arial and see if the character looks the same, then also try Courier and Courier New. I do know that those kinds of symbols vary from typeface to typeface (and the particular one used in the forms may just not have that entity at all).
    Michael
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Wilmslow, Cheshire
    Posts
    255
    Rep Power
    18
    This one's cropped up before and one slightly obscure way around it is to place the special character into a hidden form field and then alert the value of the field. The alert then displays the character rather than the code. Tried using 'unescape()' as above but that didn't work. Try adapting this:

    <SCRIPT LANGUAGE=javascript>
    <!--
    var str = "&amp;#245;";

    document.write('<FORM ID="Dave" NAME="Dave">')
    document.write('<INPUT TYPE="HIDDEN" ID="Fred" NAME="Fred" VALUE="' + str + '">')
    document.write('</FORM>')

    alert(document.forms.Dave.Fred.value)
    //-->
    </SCRIPT>

IMN logo majestic logo threadwatch logo seochat tools logo