writing in html...

B

Bad_Kid

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

Grant Wagner

Robert said:
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 <[email protected]>

* 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
 
T

Thomas 'PointedEars' Lahn

Bad_Kid said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top