469,330 Members | 1,373 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

formatting text in JavaScript popup boxes

We can use special characters ('\n') to add line breaks in text in
JavaScript popup Alert boxes.

there is also few additional special characters:

\' single quote
\" double quote
\& ampersand
\\ backslash
\n new line
\r carriage return
\t tab
\b backspace
\f form feed

Is there also additional characters for more reach formatting? (bold
text, etc)? Need we put "\n" inside quotations?
Is there some Javascript popup Alert box text formatter, to format text
from GUI, more handy way?

Apr 7 '06 #1
10 46896

ko****@hotmail.com wrote:
We can use special characters ('\n') to add line breaks in text in
JavaScript popup Alert boxes.

there is also few additional special characters:

\' single quote
\" double quote
\& ampersand
\\ backslash
\n new line
\r carriage return
\t tab
\b backspace
\f form feed

Is there also additional characters for more reach formatting? (bold
text, etc)? Need we put "\n" inside quotations?
Is there some Javascript popup Alert box text formatter, to format text
from GUI, more handy way?


If you want graphics either open a window, or display a HTML element on
top of everything else on the page.

(I myself would use the last one)

Apr 7 '06 #2
My question was about the JavaScript popup Alert boxes.

<script type="text/javascript">
alert('Text');
</script>

Apr 7 '06 #3

kor...@hotmail.com wrote:
My question was about the JavaScript popup Alert boxes.

<script type="text/javascript">
alert('Text');
</script>


Right and I answerd you.

Btw: please quote the message you're responding to.

Apr 7 '06 #4
> kor...@hotmail.com wrote:
My question was about the JavaScript popup Alert boxes.

<script type="text/javascript">
alert('Text');
</script>
Right and I answerd you. Btw: please quote the message you're responding to.

--------------------------------------------

We can use special characters ('\n') to add line breaks in text in
JavaScript popup Alert boxes.
Is there also additional characters for more reach formatting? (bold
text, etc)? Need we put "\n" inside quotations?
Is there some Javascript popup Alert box text formatter, to format text

from GUI, more handy way?

Apr 7 '06 #5
ko****@hotmail.com wrote:
We can use special characters ('\n') to add line breaks in text in
JavaScript popup Alert boxes.
True.
there is also few additional special characters:

\' single quote
\" double quote
Those are not special characters in any way. They are escape sequences
required only when the escaped character already serves as a string literal
delimiter.
\& ampersand
Well, the same goes for \a, \c, \d and so on in string literals, because it
is not a valid escape sequence. The ampersand does not need to be escaped.
\\ backslash
Again, that is not a special character, but an escape sequence for the
backslash character, which serves as escape sequence prefix itself
(hence the requirement to escape it if the literal character is needed).
\n new line
\r carriage return
\t tab
\b backspace
\f form feed
That is true, and the characters displayed by those escape
sequences are the only special characters you mentioned.

ECMAScript Edition 3 also defines the escape sequence

\v (equivalent to \u000B)

for the <VT> (Vertical Tab) character (U+000B). See ECMAScript Edition 3
Final, subsection 7.8.4.
Is there also additional characters for more reach formatting? (bold
text, etc)?
No.
Need we put "\n" inside quotations?
I do not know if you have to; I have, as I prefer to have running code.
\n is an escape sequence valid within (string and RegExp) literals only.
Is there some Javascript popup Alert box text formatter, to format text
from GUI, more handy way?


No. You will have to create your own popup window. There are some
proprietary approaches, such as showModalDialog() in the IE DOM, that
support you in creating modal windows as you know them from window.alert():

<URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/showmodaldialog.asp>

Gecko-based UAs have window.open(..., ..., "modal") and window.openDialog():

<URL:http://developer.mozilla.org/en/docs/DOM:window#Methods>

But none of these is interoperable.

And to save you another Frequently Asked Question (FAQ[1]): it is
utter nonsense to try to simulate that behavior with window.open()
by programmatically trying to force the focus on the popup window,
because that is very likely to make the rest of the GUI unusable.
PointedEars
___________
[1] <URL:http://jibbering.com/faq/>
Apr 7 '06 #6
Thomas 'PointedEars' Lahn писал(а):

ko****@hotmail.com wrote:

We can use special characters ('\n') to add line breaks in text in
JavaScript popup Alert boxes.
True.
there is also few additional special characters:

\' single quote
\" double quote
Those are not special characters in any way. They are escape sequences
required only when the escaped character already serves as a string literal
delimiter.
\& ampersand Well, the same goes for \a, \c, \d and so on in string literals, because it
is not a valid escape sequence. The ampersand does not need to be escaped.
\\ backslash
Again, that is not a special character, but an escape sequence for the
backslash character, which serves as escape sequence prefix itself
(hence the requirement to escape it if the literal character is needed).
\n new line
\r carriage return
\t tab
\b backspace
\f form feed
That is true, and the characters displayed by those escape
sequences are the only special characters you mentioned. ECMAScript Edition 3 also defines the escape sequence
\v (equivalent to \u000B)
for the <VT> (Vertical Tab) character (U+000B). See ECMAScript Edition 3
Final, subsection 7.8.4.
Is there also additional characters for more reach formatting? (bold
text, etc)?
No.
Need we put "\n" inside quotations?
I do not know if you have to; I have, as I prefer to have running code.
\n is an escape sequence valid within (string and RegExp) literals only.
Is there some Javascript popup Alert box text formatter, to format text
from GUI, more handy way?
No. You will have to create your own popup window. There are some
proprietary approaches, such as showModalDialog() in the IE DOM, that
support you in creating modal windows as you know them from window.alert():
http://msdn.microsoft.com/workshop/a...odaldialog.asp
Gecko-based UAs have window.open(..., ..., "modal") and window.openDialog():
http://developer.mozilla.org/en/docs/DOM:window#Methods
But none of these is interoperable. And to save you another Frequently Asked Question (FAQ[1]): it is
utter nonsense to try to simulate that behavior with window.open()
by programmatically trying to force the focus on the popup window,
because that is very likely to make the rest of the GUI unusable. PointedEars ___________ [1] <URL:http://jibbering.com/faq/>

------------------------------------------------------
Addind a quotations "\n" cause adding it also to text and new line
both, so it not required, probably.

Korund

Apr 7 '06 #7
ko****@hotmail.com wrote:
We can use special characters ('\n') to add line breaks
in text in JavaScript popup Alert boxes. <snip> Is there also additional characters for more reach
formatting? (bold text, etc)? Need we put "\n" inside
quotations?
Is there some Javascript popup Alert box text formatter,
to format text from GUI, more handy way?


There is quite a wide school of thought that regards the alert, prompt
and confirm facilities of web browsers as utterly inappropriate and
inadequate for use in a real world GUI; that they are at best
learning/debugging tools and should never be exposed to the end user.
This is not least because they have inconsistent and extremely limited
(and largely undesirable) display characteristics.

Richard.
Apr 7 '06 #8
Thomas 'PointedEars' Lahn wrote:
ko****@hotmail.com wrote: <snip>
\& ampersand


Well, the same goes for \a, \c, \d and so on in string literals,


This is true.
because it is not a valid escape sequence.
This is questionable. Because \a is a valid EscapeSequence (ECMA 262,
3rd Ed. Section 7.8.4). The backslash followed by EscapeSequence, where
EscapeSequence is one of 0, CharacterEscapeSequence, HexEscapeSequence
or UnicodeEscapeSequence is a SingleStringCharacter. And
CharacterEscapeSequence is either SingleEscapeCharacter or
NonEscapeCharacter, where NonEscapeCharacter is any SourceCharacter that
is not an EscapeCharacter or LineTerminator.

So any character (with the explicit exception of LineTerminators)
preceded by a backslash may be a valid EscapeSequence but if the
character is not one of the set that is SingleEscapeCharacter the result
of the EscapeSequence is just the character itself.

\a is the equivalent of a, pointless but allowed by the syntax.
The ampersand does not
need to be escaped.
No it does not need to be escaped.

<snip> ECMAScript Edition 3 also defines the escape sequence

\v (equivalent to \u000B)

for the <VT> (Vertical Tab) character (U+000B). See
ECMAScript Edition 3 Final, subsection 7.8.4.

<snip>

True, but as I recall IE gets this wrong and treats \v as a literal v.
Still, how often have you used vertical tabs to date? For me it is
never, and that is one of the reasons that I use vertical tabs
('\u000B') as separators in strings that need to be split up using a
character separator, as alternatives such as |, ~, ^, etc. have proved
insufficiently unusual in the past.

Richard.
Apr 7 '06 #9
> Addind a quotations "\n" cause adding it also to text and new line
both, so it not required, probably.

----------------------
Hence, correct syntax is without double quotations, i.e. \n , \r , etc

Korund

Apr 7 '06 #10
JRS: In article <11**********************@t31g2000cwb.googlegroups .com>
, dated Fri, 7 Apr 2006 03:51:20 remote, seen in
news:comp.lang.javascript, ko****@hotmail.com posted :

Is there also additional characters for more reach formatting? (bold
text, etc)?


AFAIK no, apart maybe from \v .

However, AFAICS no-one has yet mentioned the use of \uHHHH where H is a
hexadecimal digit - try alert("\u20ac") - though it may be that not many
of them work reliably (user font dependence).
--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Apr 8 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Treetop | last post: by
3 posts views Thread by Ike | last post: by
5 posts views Thread by Paul Krasucki | last post: by
2 posts views Thread by one.1more | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.