writing in html...

Discussion in 'Javascript' started by Bad_Kid, Jul 7, 2004.

  1. Bad_Kid

    Bad_Kid Guest

    how can I write text (chars) through numbers - (using ascii table)?? -
    whaat's the function that does conversion int-> char?
    Bad_Kid, Jul 7, 2004
    #1
    1. Advertising

  2. Bad_Kid

    Grant Wagner Guest

    Robert wrote:

    > In article <ccfm4a$rcs$>,
    > "Bad_Kid" <> wrote:
    >
    > > how can I write text (chars) through numbers - (using ascii table)?? -
    > > whaat's the function that does conversion int-> char?

    >
    > var i = 1;
    >
    > alert(""+i);
    >
    > In the case where you concatenate a string to a number, the result will
    > be a string.
    >
    > alert(i);
    >
    > In most instances, JavaScript will correctly convert a number from
    > integer to character as you expect.
    >
    > Robert


    I think what he means is he has int values between 65 and 90 inclusive (for
    example), and wants to output the characters those integer values represent
    in the "ascii" table.

    To do that, he needs the static fromCharCode() method of the String object:

    <script type="text/javascript">
    for (var i = 65; i <= 90; i++) {
    document.write(String.fromCharCode(i) + '<br>');
    }
    </script>

    --
    | Grant Wagner <>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *
    http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

    * Internet Explorer DOM Reference available at:
    *
    http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

    * Netscape 6/7 DOM Reference available at:
    * http://www.mozilla.org/docs/dom/domref/
    * Tips for upgrading JavaScript for Netscape 7 / Mozilla
    * http://www.mozilla.org/docs/web-developer/upgrade_2.html
    Grant Wagner, Jul 7, 2004
    #2
    1. Advertising

  3. Bad_Kid wrote:
    > how can I write text (chars) through numbers - (using ascii table)?? -
    > whaat's the function that does conversion int-> char?


    All numbers in ECMAScript and its implementations are double-precision
    (64 bit) floating-point numbers. There are no real integers like in C
    etc. and there is no "int" or "char" type ("char"s are strings of length
    1). However, if you regard a floating-point number with a fractional
    part of zero an integer value, then

    String.fromCharCode(integer_value)

    will use not only US-ASCII (7 bit) but also either ISO-8859-1 (8 bit),
    the character encoding of the current locale or Unicode (UTF-16, 16
    bit), depending on the implementation. Another way are string literals
    where the same applies:

    "\x20"

    equals the space character (" ") and

    "\u20AC"

    equals the Euro sign as of Unicode.

    This is a very basic question, please read the
    guides and specs before you post next time.

    The ECMAScript specifications are available at
    <http://www.mozilla.org/js/language/>

    JavaScript Guides and References are available at
    <http://devedge.netscape.com/central/javascript/>

    The JScript Reference is available at
    <http://msdn.microsoft.com/library/>

    See the FAQ <http://jibbering.com/faq/> which is
    posted here regularly.


    HTH

    PointedEars
    Thomas 'PointedEars' Lahn, Jul 11, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Avi

    writing html (client) on aspx

    Avi, May 5, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    589
  2. Mark

    Re: writing HTML directly

    Mark, Jul 8, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    396
  3. Marc Hoeppner

    Re: Writing HTML Page

    Marc Hoeppner, Jul 22, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    357
    Charles Rumbold
    Jul 22, 2003
  4. HNguyen
    Replies:
    4
    Views:
    2,399
    HNguyen
    Dec 21, 2004
  5. Adam Akhtar
    Replies:
    9
    Views:
    522
    Florian Gilcher
    Aug 16, 2008
Loading...

Share This Page