473,787 Members | 2,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unable to get line-breaks for a JavaScript 'alert' message using ClientScript.Re gisterStartUpSc ript

Hi All,

I'm trying to create a function that will cause a pop-up alert to
appear if dates which were chosen from a drop-down list were invalid
on a page. There's 4 dates, so there's the possibility of 4 errors at
once. I'd like to pop-up all the errors at once, so the user can
correct all the errors at once. My issue is format. I'd like a
message something like...

ERROR: Acquired Date Invalid - only 28 days in February for year
chosen
ERROR: Disposition Date Invalid - only 30 days in the month, or wrong
month chosen
ERROR: License Expiration Date Invalid - only 29 days in February for
year chosen
ERROR: Support Expiration Date Invalid - only 28 days in February for
year chosen

.... that's using line breaks. In normal JavaScript I'd do something
like this...
alert("Hello again! This is how we" + '\n' + "add line breaks to an
alert box!")

.... however, for some reason I can't get the escape sequence to
properly generate the line breaks. So all the error messages get
mushed together. I've tried adding the '\n' in a multitude of ways,
but it always gets messed. Most of the time it just won't work at
all... with the pop-up that is. It'll still return the proper boolean
value, just no pop-up alert. Has anyone else run across this issue
and solved it? Is there a better way of doing this? Any help or
insight would be appreciated.

I'm posting my code below so that you know what I'm talking about :)
// informationIsVa lid()
// Description: goes through the information entered to make
sure it's valid.
// If it's valid, then the information can be submitted to the
database. If not,
// an error message is displayed
protected bool informationIsVa lid()
{
string alertMessage = "";
string alertScript;
bool isValid = true;

try
{
// check if Acquired Date is valid
if (ddl_AcquiredDa y.SelectedIndex 29 &&
ddl_AcquiredMon th.SelectedInde x == 2 &&
DateTime.IsLeap Year(ddl_Acquir edYear.Selected Index))
{
alertMessage += "ERROR: Acquired Date Invalid - only
29 days in February for year chosen";
isValid = false;
}

if (ddl_AcquiredDa y.SelectedIndex 28 &&
ddl_AcquiredMon th.SelectedInde x == 2 &&
!DateTime.IsLea pYear(ddl_Acqui redYear.Selecte dIndex))
{
alertMessage += "ERROR: Acquired Date Invalid - only
28 days in February for year chosen";
isValid = false;
}
// April =4, June = 6, Sept = 9, Nov = 11... these
months only have 30 days to them
if ((ddl_AcquiredM onth.SelectedIn dex == 4 ||
ddl_AcquiredMon th.SelectedInde x == 6 ||
ddl_AcquiredMon th.SelectedInde x == 9 ||
ddl_AcquiredMon th.SelectedInde x == 11) &&
ddl_AcquiredDay .SelectedIndex 30)
{
alertMessage += "ERROR: Acquired Date Invalid - only
30 days in the month, or wrong month chosen";
isValid = false;
}
// check if Dispostion Date is valid
if (ddl_Dispositio nDay.SelectedIn dex 29 &&
ddl_Disposition Month.SelectedI ndex == 2 &&
DateTime.IsLeap Year(ddl_Dispos itionYear.Selec tedIndex))
{
alertMessage += "ERROR: Disposition Date Invalid -
only 29 days in February for year chosen";
isValid = false;
}

if (ddl_Dispositio nDay.SelectedIn dex 28 &&
ddl_Disposition Month.SelectedI ndex == 2 &&
!
DateTime.IsLeap Year(ddl_Dispos itionYear.Selec tedIndex))
{
alertMessage += "ERROR: Disposition Date Invalid -
only 28 days in February for year chosen";
isValid = false;
}
if ((ddl_Dispositi onMonth.Selecte dIndex == 4 ||
ddl_Disposition Month.SelectedI ndex == 6 ||
ddl_Disposition Month.SelectedI ndex == 9 ||
ddl_Disposition Month.SelectedI ndex == 11) &&
ddl_Disposition Day.SelectedInd ex 30)
{
alertMessage += "ERROR: Disposition Date Invalid -
only 30 days in the month, or wrong month chosen";
isValid = false;
}
if (ddl_LicenseExp irationDay.Sele ctedIndex 29 &&
ddl_LicenseExpi rationMonth.Sel ectedIndex == 2 &&

DateTime.IsLeap Year(ddl_Licens eExpirationYear .SelectedIndex) )
{
alertMessage += "ERROR: License Expiration Date
Invalid - only 29 days in February for year chosen";
isValid = false;
}

if (ddl_LicenseExp irationDay.Sele ctedIndex 28 &&
ddl_LicenseExpi rationMonth.Sel ectedIndex == 2 &&
!
DateTime.IsLeap Year(ddl_Licens eExpirationYear .SelectedIndex) )
{
alertMessage += "ERROR: License Expiration Date
Invalid - only 28 days in February for year chosen";
isValid = false;
}

if ((ddl_LicenseEx pirationMonth.S electedIndex == 4 ||
ddl_LicenseExpi rationMonth.Sel ectedIndex == 6 ||
ddl_LicenseExpi rationMonth.Sel ectedIndex == 9 ||
ddl_LicenseExpi rationMonth.Sel ectedIndex == 11) &&
ddl_LicenseExpi rationDay.Selec tedIndex 30)
{
alertMessage += "ERROR: License Expiration Date
Invalid - only 30 days in the month, or wrong month chosen";
isValid = false;
}

if (ddl_SupportExp irationDay.Sele ctedIndex 29 &&
ddl_SupportExpi rationMonth.Sel ectedIndex == 2 &&

DateTime.IsLeap Year(ddl_Suppor tExpirationYear .SelectedIndex) )
{
alertMessage += "ERROR: Support Expiration Date
Invalid - only 29 days in February for year chosen";
isValid = false;
}

if (ddl_SupportExp irationDay.Sele ctedIndex 28 &&
ddl_SupportExpi rationMonth.Sel ectedIndex == 2 &&
!
DateTime.IsLeap Year(ddl_Suppor tExpirationYear .SelectedIndex) )
{
alertMessage += "ERROR: Support Expiration Date
Invalid - only 28 days in February for year chosen";
isValid = false;
}

if ((ddl_SupportEx pirationMonth.S electedIndex == 4 ||
ddl_SupportExpi rationMonth.Sel ectedIndex == 6 ||
ddl_SupportExpi rationMonth.Sel ectedIndex == 9 ||
ddl_SupportExpi rationMonth.Sel ectedIndex == 11) &&
ddl_SupportExpi rationDay.Selec tedIndex 30)
{
alertMessage += "ERROR: Support Expiration Date
Invalid - only 30 days in the month, or wrong month chosen";
isValid = false;
}
}
catch (Exception err)
{
lbl_status.Text = "An error occurred: ";
lbl_status.Text += err.Message;
}

if (!isValid)
{
alertScript = "<script language=JavaSc ript>alert('" +
alertMessage + "')</script>";
ClientScript.Re gisterStartupSc ript(this.GetTy pe(), "Alert
Message", alertScript);
return false;
}
else
{
return true;
}

}

Thanks,
Wayne

Feb 4 '07 #1
3 3961
Hello,

Try using "\r\n".

Regards
Bjorn.

Feb 4 '07 #2
On 4 Feb 2007 01:15:59 -0800, "Wayne Deleersnyder"
<wa***@digitalm eister.comwrote :

[snip]

Try Environment.New Line

rossum

Feb 4 '07 #3
On Feb 4, 5:48 am, rostercapt...@g mail.com wrote:
Hello,

Try using "\r\n".

Regards
Bjorn.
Woot! Thank Bjorn. I actually used "\\r\\n" but it did the trick.

Thanks for the help.
Wayne D.

PS - sorry for getting back so late.

Feb 6 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
13291
by: Nancy | last post by:
Hi, When I start my PC(winXP Pro), it always says: Unknown(): Unable toload dynamic library './php_msql.dll' - The specified module could not be found. Then my Apache servre starts, load php module and works well. I copied php_msql.dll to my system32 directory. Who knows what's wrong? Thanks a lot?
1
7309
by: Oliver Spiesshofer | last post by:
Hi, I am trying to load the LDAP and the MCrypt module under WinXP and PHP Version 4.3.7. The strange thing is that I have several other modules that work just fine: extension=php_bz2.dll extension=php_gd2.dll extension=php_mbstring.dll
5
6344
by: Maett | last post by:
Hi. When I try to compile this piece of Code with VC.NET 2003 // code start #include <vector> template< class T > struct Marker { public:
1
2817
by: Jim | last post by:
I have the following code: Line 35: Dim sURL As String = "http://www.google.com" Line 36: Dim data As Stream = client.OpenRead(Server.UrlPath­Encode(sURL)) Line 37: Dim reader As New StreamReader(data) Line 38: Results = reader.ReadToEnd()
0
12068
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in '/CinemaBookingSystem' Application. -------------------------------------------------------------------------------- ERROR General error Unable to open registry key 'Temporary (volatile) Jet DSN for process
5
15727
by: Arno | last post by:
reposted with the right microsoft managed newsgroup ID: Sorry for the inconvinience Hi, I've written a class for client-socket connection, but I get a lot of times the error message "Unable to read data from the transport connection" when restart reading the stream with socket.BeginRead in the Sub SocketIncomingMsg. I'm debugging now for weeks, but I can't detect where it's
6
10003
by: Varlamov Konstantyn | last post by:
I have simple script: <?php $connection = ssh2_connect("ip", 22); ssh2_auth_password($connection,"login","test");
6
6803
Markus
by: Markus | last post by:
I'm adding to my script a section that allows a thumbnail to be created and saved. I get this error: Warning: imagejpeg() : Unable to open '../uploads/thumb/' for writing: Is a directory in /home/.gobbles/mahcuz/mahcuz.com/upload/uploaded.php on line 129 And this is some of the code from the page: /* New code for thumbnails. Will on work if user selects "create thumb on upload" on the upload page */ //check to see if checkbox is...
3
6270
by: Harmony504 | last post by:
HELP! Setup: PHP5.2.5, IIS 5.1, XP, AS/400 (DB/400 or DB2) I am trying to connect to a DB2 database from my computer. I installed DB2 Connect and set up the ODBC Driver in the Data Source Administrator. I uncommented the extension=php_ibm_db2.dll line in my php.ini file. <?php $DBName = "WSC520"; // The name of the database ...
4
5914
by: keirnus | last post by:
Hello, I've been coding in Access VBA to create an Excel Graph and it was good. Until I got this error: Please check the code below: Private Sub TestGraph3()
0
9655
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.