Geeks With Blogs

News

Microsoft MVP


DZone MVB


Moderator at CodeASP.NET


Quiz Master







free counters
Free counters
Added on January 19,2012


Follow Me @vmsdurano

A bit About Me



Disclaimer
The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.


Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"

Ok it seems that lot’s of members at the forums is asking on how to display multi-line text in a JavaScript pop up box. So I decided to write this example so that other developers can reference it or if I encounter such a post in the forum then I can simply point them in this example.

 

Check the following code blocks below:

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Untitled Page</title>

    <script type="text/javascript" language="javascript">

        function ShowBoxWithConfirm()

        {

            var msg1 = "Message 1";

            var msg2 = "Message 2";

            var msg3 = "Message 3";

            if (confirm(msg1 + "\n" + msg2 + "\n" + msg3) == true)

            {return true;}

            else

            {return false;}

        }

        function ShowBox()

        {

            var msg1 = "Message 1";

            var msg2 = "Message 2";

            var msg3 = "Message 3";

            alert(msg1 + "\n" + msg2 + "\n" + msg3);

        }

    </script>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <asp:Button ID="Button1" runat="server" Text="Using Confirm" OnClientClick="return ShowBoxWithConfirm();" />

        <br />

        <asp:Button ID="Button2" runat="server" Text="Using Alert" OnClientClick="ShowBox();" />

    </div>

 

</form>

</body>

</html>

 

The trick there is we used, “\n” for creating a new line in a JavaScript. You can also use “\r” or “\r\n” for creating a new line in a set of strings.

 

Running the code above will show something like below in the page:

 

Using Confirm:

 

 

Using Alert:

 

 

That’s it! Hope you will find this example useful!

 

Technorati Tags: ,,
Posted on Monday, August 3, 2009 4:45 PM ASP.NET , JavaScript , Tips&Tricks | Back to top


Comments on this post: Adding Line Breaks in JavaScript Alert and Confirm popup Message in ASP.NET

# re: Adding Line Breaks in JavaScript Alert and Confirm popup Message in ASP.NET
Requesting Gravatar...
Vastly underused - these javascript popups used to be everywhere in web apps - you barely see unskinned ones anymore
Left by used macbooks on Aug 03, 2009 11:02 PM

# re: Adding Line Breaks in JavaScript Alert and Confirm popup Message in ASP.NET
Requesting Gravatar...
JAVASCRIPT FTW¬!!!!
Left by microprojector reviews on Aug 03, 2009 11:03 PM

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: GeeksWithBlogs.net