?
Solved

Formatting of text given as input to the JavaScript alert function

Posted on 2006-11-23
4
Medium Priority
?
2,220 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 375 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
Suggested Courses

752 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