Page 1 of 1
line breaks in Javascript alert()
Posted: Fri Sep 02, 2005 5:49 am
by raghavan20
Alright, I have set up alerts at various points in my application.
I am trying to display a multi-line message in the alert box which is done by using "\n" as line breaks.
I have personally worked with line breaks in alert before and they worked but i am not able to figure out the problem with this one.
This is a calendar application, you can see a few dates in it being highlighted/anchored and I have set up alerts for those, which do not happen.
on view source, the alert message looks alright and here is the alert output
page:
http://raghavan.100webcustomers.com/Calendar1.class.php
Code: Select all
onclick='alert("This is the URL you give as input.
the action can be anything like editPost/viewPost/viewAppointment/viewBlog/viewBirthday.
The id can be post_id, blog_id, appointment_id, birthday_record_id.
yourfilename.ext?action=youraction&id=32");'
Posted: Fri Sep 02, 2005 6:48 am
by anjanesh
I dont think your onclick event gets parsed like that.
No sure abt this, but Im sure that
<sp an>text</sp an> is not parsed as
<span>text</span>.
Why dont you replace
Code: Select all
onclick='alert("This is the URL you give as input.
the action can be anything like editPost/viewPost/viewAppointment/viewBlog/viewBirthday.
The id can be post_id, blog_id, appointment_id, birthday_record_id.
yourfilename.ext?action=youraction&id=32");'
with
Code: Select all
onclick='alert("This is the URL you give as input.\n the action can be anything like \n editPost/viewPost/viewAppointment/viewBlog/viewBirthday.\n The id can be post_id, blog_id, appointment_id, birthday_record_id.\n yourfilename.ext?action=youraction&id=32");'
Posted: Fri Sep 02, 2005 6:56 am
by raghavan20
alright let me give you more information
Code: Select all
$message = "This is the URL you give as input.\n the action can be anything like editPost/viewPost/viewAppointment/viewBlog/viewBirthday.\n";
$message .= "The id can be post_id, blog_id, appointment_id, birthday_record_id.\n";
echo "<span><a href='".$this->redirectLink.$tempArray[$i]." ' onclick='alert(\"".$message.$this->redirectLink.$tempArray[$i]."\");' class='links'>$i</a></span>";
edit: the problem is, rather interpreting the \n within the alert box, the messages was interpreted earlier and alert can not understand the message which has got several lines.
now i need to know how to format the above message so that the alert interprets by itself.
Posted: Fri Sep 02, 2005 7:11 am
by anjanesh
Since \n in $message is parsed on the server side - PHP part, you'll need to replace \n with \\n
Posted: Fri Sep 02, 2005 7:53 am
by raghavan20
yeah....that solved my problem. thanks very much anjanesh.
I feel bad that I could not think of it.

Posted: Fri Sep 02, 2005 7:54 am
by feyd
added info: if the carriage return is output in the string (not using \n), Javascript doesn't support multi-line strings.
Posted: Sun Sep 04, 2005 11:38 am
by pilau
Raghavan20, I noticed some problems with your calendar.
First of all, you can only get to January 2050 and not further. If you click next you will get to January 1970 (UNIX timestamp anyone?)
Second, If you are on January 1970, and you click previous, you won't go back to Jan 2050. Don't know whther it's an error or not, but thats all.
Posted: Mon Sep 05, 2005 5:59 am
by raghavan20
pilau, I had a regex script to validate year and month and I earlier had the limit from 1900-2050. now I have increased it from 1800 - 2060