473,320 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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
4 3978
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


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

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

Jul 23 '05 #3

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Joris De Groote | last post by:
Hi, I have a 1 dimensional table byte with a number af characters in ASCII code. How do I convert those ASCII codes to real letters? Thanks
19
by: many_years_after | last post by:
Hi,everyone: Have you any ideas? Say whatever you know about this. thanks.
3
by: umdsasha | last post by:
So, basically, I need to detect whether an alert window was thrown. I can't find where it's thrown from but I need to disable a button only if there were no alert windows thrown. Any ideas? ...
1
by: vandy1285 | last post by:
Hello friends.. Is it posssbile to change the layout of the default alert window.....as in i want to change the font color,font size,background color of alert window... is it possible....
4
by: Phil | last post by:
Hi, The Alert window appears but the value is "undefined". I tried two ways What don't i see here? Thanks Phil <html xmlns="http://www.w3.org/1999/xhtml" > <head...
6
by: Phil | last post by:
Hi, This code produces an empty Alert window. No error. How to get the value into the Alert window? Thanks Phil aspx file (content page): ------------------------
1
by: gabrielk43 | last post by:
My question is this: I use Flex Builder 2 and actionscript 2. Suppose that I have created a simple alert window like that: var alertWindow:Alert = Alert.Show(message);. What if I want to close...
1
by: cruzzer | last post by:
I need to know how can I exclude a data item from the Alert Window’s list message if the user leaves a prompt window blank. Example : If the user types a value to both “idnumber” and...
3
by: yogesh6585 | last post by:
How can i close alert box automatically without user iteration? i call the another method but javascript execute code continue and i need to stop the execution for 5 to 10 second, i can not use...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.