Results 1 to 4 of 4
  1. #1
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Defining characters in JavaScript

    Or, more probably, in HTML!

    So far I find I can define characters in three ways:
    1) as an ASCII character, as in "a"
    2) as a unicode constant, as in 00uu
    3) as a decimal constant, as in &#nn;

    My attempt at another way:
    4) in 'URL format', as in %xx
    doesn't work. Can this be made to work, and/or is there any other way of specifying a character?

    Any comments from knowledgeable JavaScriptians, please? My test file is attached, renamed from .HTM to .TXT, rather than inline, because of the effects the Lounge has on such code...

    Thanks

    John

    PS But the Lounge modifies even TXT files...!
    Attached Files Attached Files
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Defining characters in JavaScript

    Yes, the Lounge protects you against malicious code even if you don't want it. <img src=/S/evilgrin.gif border=0 alt=evilgrin width=15 height=15>

    You can use String.fromCharCode to return the character belonging to a code, e.g.

    mystring=String.fromCharCode(98)+String.fromCharCo de(53);

    results in 'b5'.

    PS Wouldn't someone proficient in JavaScript be a JavaScribe?

  3. #3
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Defining characters in JavaScript

    Thanks, Hans!

    I was working at a simpler level than using functions, and haven't really been able to find anything which describes the allowable 'character definition' methods (in my terminology). I was trying to find all possible ways of defining a character as a first stage, with the second stage being how to generate the code to produce the character definition. A bit backwards, but there you are.

    Now if you're intimately familiar with the sorting of three-dimensional arrays (on the second or third dimension/column) in Javascript I'd be interested!

    I suppose JavaScribe would be the best term, but my JavaScriptian was an echo of BigEndian and LittleEndian... (Yes, OK, one of the Two Little Endians!).

    John
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  4. #4
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Defining characters in JavaScript

    Hi John I think I read you right, my apologies if not.

    What you need to use is the encodeURI() function

    Here is a sample code you may want to run for to show how a space can be converted to in a URL

    <pre><html>
    <head>
    </head>
    <body>

    <script type="text/javascript">

    document.write(encodeURI("http://www.wopr.com")+ "")
    document.write(encodeURI("http://www.magicforest.co.uk/Stuff on URI/")+ "")
    document.write(encodeURI(",/?:@&=+$#"))


    </script>



    </body>
    </html>
    </pre>



    The list , / ? : @ & = + $ # is not a swear word but characters that cannot be encoded which may explain a few things
    This link will take you to the values that are acceptable in the %nn series urlencode

    If I have missed your point, sorry, been a long day.
    Jerry

Posting Permissions

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