Solved

Formatting of text given as input to the JavaScript alert function

Posted on 2006-11-23
4
2,216 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

696 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