[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Formatting of text given as input to the JavaScript alert function

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

656 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