Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Sep 2002
    Location
    Detroit, Michigan, USA
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Equivalent Javascript function

    What's the Javascript equivalent of the VB function Asc() ?. All literature I checked points to fromCharCode() but if I insert an appropriate number as argument, the function won't return a valid character. Thanks in advance.

  2. #2
    5 Star Lounger
    Join Date
    Apr 2003
    Location
    Hampshire, United Kingdom
    Posts
    602
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Equivalent Javascript function

    fromCharCode is the correct function to use.

    If you enter the following in a web page, the result is <span style="background-color: #FFFF00; color: #000000; font-weight: bold">abc</span hi>:
    <div style="width: 100%; background-color: #FFFFFF;">
    <script type=text/javascript>
    document.write(String.fromCharCode(97,98,99));
    </script>
    </div hiblock>

    (Working example)
    Waggers
    If at first you do succeed, you&#39;ve probably missed something.

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

    Re: Equivalent Javascript function

    I don't know JavaScript, but fromCharCode seems to be more or less related to Chr. The function related to Asc is probably charCodeAt:

    function charCodeAtTest(n){
    var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //Initialize variable.
    return str.charCodeAt(n - 1); //Return Unicode value of the n-th character.
    }

  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: Equivalent Javascript function

    <P ID="edit" class=small>(Edited by Jezza on 17-Feb-06 10:34. Altered to change tag formatting-Thanks for the tip Hans)</P>Hi Raul

    You could use the unescape() method to convert a Hexadecimal value to its ASCII equivalent

    <script language="JavaScript">
    var escapedVal="%40";


    var escapedVal=unescape(escapedVal);

    document.write('The escapedVal value (' + escapedVal + ") ");
    document.write ("evaluates to " + unescapedVal);

    </script>



    You can write up the method so that the escapedVal becomes variable you will get a document write
    Jerry

  5. #5
    Star Lounger
    Join Date
    Sep 2002
    Location
    Detroit, Michigan, USA
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Equivalent Javascript function

    Thanks everybody for the input.

Posting Permissions

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