Solved

Formatting of text given as input to the JavaScript alert function

Posted on 2006-11-23
4
2,209 Views
Last Modified: 2012-08-14
Hello,

Does anybody know if it's possible to format what gets displayed when calling the alert method - eg. if I wanted some part of the text written in red?

Regards
JB
0
Comment
Question by:JohnBak
4 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 18004314
As far as I know, it is impossible to format anything in alert(). The closest you could get is some sort of <div> or a new window that is styled to look like an alert box.

Of course, if you wanted for IE, you could use showModalDialog: http://www.webreference.com/js/column90/index.html
0
 
LVL 7

Expert Comment

by:vbandaru
ID: 18004492
i.e is right. You cannot make the alert box itself red, However you can create something so close to the alert box using the modaldialogbox.
0
 
LVL 3

Expert Comment

by:viveksg
ID: 18006181
Yeah, no such formatting in alert box. But you can split your message into two lines by adding \n between the words.

e.g: alert("My first line\nMy second line");
0
 
LVL 23

Accepted Solution

by:
rama_krishna580 earned 125 total points
ID: 18011938
Try this example:

<html>
<head>

<script>
function stylealert(){
placement.innerHTML=message.newalert.value
}
</script>

</head>
<body>

<form name="message">

<!-- PUT YOUR ALERT AS A FIXED SIZED DIV INSIDE THIS CSS-HIDDEN TEXTAREA -->

<textarea name="newalert" style="visibility:hidden">
<div style="width:256px; height:170px; background-color:yellow; border:solid
1px black;"onClick="this.style.visibility='hidden'">
<br>
<center>
<b>
A new kind of alert box
</b>
<br>
<br>
<br>
Click to Close
</center>
</div>
</textarea>

<input type="button" value="Click for alert" onClick="stylealert()">
</form>

<!-- IF YOU WANT TO POSITION THE ALERT DIV USE CSS - position:absolute;
left:Xpx; top:Xpx -->
<!-- OR USE JAVASCRIPT TO DETERMINE THE CENTER OF THE SCREEN-->
<a name="placement"></a>

</body>
</html>

R.K
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question