By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,628 Members | 1,696 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,628 IT Pros & Developers. It's quick & easy.

Displaying upper ASCII (code 128-255) in alert() window.

P: n/a
Most of these characters are not on the standard keyboard.
Here's a successful contrivance, with comments & cautions,
a little page that works in IE6.

<HTML><HEAD><SCRIPT TYPE="text/javascript">
function alt() {
document.all.s1.innerHTML="Current Temp: 68°F";
var txt=document.all.s1.innerText;
alert(txt);
}
</SCRIPT></HEAD>
<BODY>
<INPUT TYPE="button" VALUE="Temperature" onClick="alt()">
<P ID="s1" STYLE="visibility:hidden"> </P>
</BODY></HTML>

comments: The innerHTML property is needed to produce the
character glyph from the entity code. If the entity string
were passed to innerText(in 1st statement) then the code
would remain literal.
This work-around depends on s1 being rendered before alt()
is called. It will not work as immediately executed code,
because element s1 would not exist yet.

cautions: Trying to style alert's display will produce error
msgs. Do not use <B>, <U>, or <I> tags in the argument
string. No Heading tags either.
Strange enough, an inline STYLE, setting font values, say,
does not give error msg, but will not execute either.
Alert ignores it.
You can use <BR> tags in the argument, which give the same
result as \n in a direct arg to alert().

In sum, you can tell alert what characters to display,
in what order, and on what line, but you cannot tell
alert HOW to display them.

hugo2, March 4, 2005

Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
hugo2 wrote:
Most of these characters are not on the standard keyboard.
Here's a successful contrivance, with comments & cautions,
a little page that works in IE6.
Define "works". It does not "work" for me in IE6 on WinXP SP2.

Before posting code, you should at minimum validate the HTML and test it.
<HTML><HEAD><SCRIPT TYPE="text/javascript">
function alt() {
document.all.s1.innerHTML="Current Temp: 68°F";
IE only.
var txt=document.all.s1.innerText;
IE only.
alert(txt);
}
function oneThatWorks(){
document.getElementById('s1').innerHTML="Current Temp: 68°F";
var txt= document.getElementById('s1').innerHTML;
alert(txt);
}

Now, it is tested to work in IE6, Opera 7 and Mozilla.
</SCRIPT></HEAD>
<BODY>
<INPUT TYPE="button" VALUE="Temperature" onClick="alt()">
Object does not support this method.

As reported by IE6 when given a strict doctype.
<P ID="s1" STYLE="visibility:hidden"> </P>
</BODY></HTML>

comments: The innerHTML property is needed to produce the
character glyph from the entity code. If the entity string
were passed to innerText(in 1st statement) then the code
would remain literal.
This work-around depends on s1 being rendered before alt()
is called. It will not work as immediately executed code,
because element s1 would not exist yet.
See above. Reading this groups FAQ will show you how to insert, and
read, text from a div tag in most major browsers without resorting to IE
only code, even though it uses the semi-proprietary (non-standard) innerHTML
cautions: Trying to style alert's display will produce error
msgs. Do not use <B>, <U>, or <I> tags in the argument
string. No Heading tags either.
Who told you that garbage?

alert('This has a <B>, a <U> and an <I> tag in it, test it!')
Strange enough, an inline STYLE, setting font values, say,
does not give error msg, but will not execute either.
Alert ignores it.
Thats because you can't "style" an alert. If you want style, write your
own alert div tag in the page.
You can use <BR> tags in the argument, which give the same
result as \n in a direct arg to alert().


BULL. Test before you post.

alert('This has a <BR> tag but no line break in the alert, test it!')

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Jul 23 '05 #2

P: n/a


The easiest way to display characters not on the keyboard is simply:

alert('Current Temp: 68' + String.fromCharCode(176));

Jul 23 '05 #3

P: n/a

Randy Webb wrote:
hugo2 wrote:
Most of these characters are not on the standard keyboard.
Here's a successful contrivance, with comments & cautions,
a little page that works in IE6.
Define "works". It does not "work" for me in IE6 on WinXP SP2.

Before posting code, you should at minimum validate the HTML and test

it.
<HTML><HEAD><SCRIPT TYPE="text/javascript">
function alt() {
document.all.s1.innerHTML="Current Temp: 68°F";
IE only.
var txt=document.all.s1.innerText;


IE only.
alert(txt);
}


function oneThatWorks(){
document.getElementById('s1').innerHTML="Current Temp: 68°F";
var txt= document.getElementById('s1').innerHTML;
alert(txt);
}

Now, it is tested to work in IE6, Opera 7 and Mozilla.
</SCRIPT></HEAD>
<BODY>
<INPUT TYPE="button" VALUE="Temperature" onClick="alt()">


Object does not support this method.

As reported by IE6 when given a strict doctype.
<P ID="s1" STYLE="visibility:hidden"> </P>
</BODY></HTML>

comments: The innerHTML property is needed to produce the
character glyph from the entity code. If the entity string
were passed to innerText(in 1st statement) then the code
would remain literal.
This work-around depends on s1 being rendered before alt()
is called. It will not work as immediately executed code,
because element s1 would not exist yet.


See above. Reading this groups FAQ will show you how to insert, and
read, text from a div tag in most major browsers without resorting to

IE only code, even though it uses the semi-proprietary (non-standard) innerHTML
cautions: Trying to style alert's display will produce error
msgs. Do not use <B>, <U>, or <I> tags in the argument
string. No Heading tags either.
Who told you that garbage?

alert('This has a <B>, a <U> and an <I> tag in it, test it!')
Strange enough, an inline STYLE, setting font values, say,
does not give error msg, but will not execute either.
Alert ignores it.


Thats because you can't "style" an alert. If you want style, write

your own alert div tag in the page.
You can use <BR> tags in the argument, which give the same
result as \n in a direct arg to alert().
BULL. Test before you post.

alert('This has a <BR> tag but no line break in the alert, test it!')

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup

weekly Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?


hugo2 March 7, 2004
My apologies to everyone. The one problem with my post
is the function name: alt(). This one name does not work
(I had use several different names) because *alt* turns
out to be an HTML attribute, a rather obscure one in <IMG>,
but I should have checked!
All the other statements I made were derived from testing,
and they are all true, in the context of passing an HTML
fragment containing non-keyboard glyph to alert().
I was not talking about general use of alert().
If interested parties would change the function name to
at() or atl() or go(), then the page works fine,
though you would have to adapt it for other browsers.

hugo2 --

Jul 23 '05 #4

P: n/a
hugo2 wrote:
Randy Webb wrote:

<snip>
function oneThatWorks(){
document.getElementById('s1').innerHTML="Curre nt Temp: 68°F";
var txt= document.getElementById('s1').innerHTML;
alert(txt);
}

Now, it is tested to work in IE6, Opera 7 and Mozilla.


<snip>
If interested parties would change the function name to
at() or atl() or go(), then the page works fine,
though you would have to adapt it for other browsers.


No need, I gave one that works (and tested) in IE6, Opera 7 and Mozilla,
so its just a matter of copy/paste. Although mine could stand a little
more feature detection before relying on getElementById and innerHTML
(although there has been no definitive test to ensure that changing an
elements innerHTML property actually changes it's visual appearance).

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.