/    Sign up×
Community /Pin to ProfileBookmark

How to create two line alert

I want to create an alert with two lines
Today’s Date
Sat March 3 12:35:58 EST 2012

I have used syntax alert(“Today’s date is : </br> “+dt);
and alert(“Today’s date is : “+<br />dt);

But none is working. Is it possible to create two line alert ? If yes, how ?

[code]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” lang=”en” xml:lang=”en” >
<head>

<title>Javascript Assignment 1</title>

<script type=”text/javascript”>

function backgcolor(){
document.bgColor=”#ff0000″;
}

function txtcolor(){
document.fgColor=’green’;
}

function alertfn(){
alert(“This is test alert”);
}

function displayDate(){
var dt = new Date();
alert(“Today’s date is : “+dt);
}

function writeDate(){
var dt = new Date();
document.write(dt);
}
</script>
</head>

<body>
<p>
<input type=”button” value=”Change Background Color” onclick=”backgcolor()” />
<input type=”button” value=”Change Text Color” onclick=”txtcolor()” />
<input type=”button” value=”Test Alert” onclick=”alertfn()” />
<input type=”button” value=”Get Date” onclick=”displayDate()” />
<input type=”button” value=”Write Date” onclick=”writeDate()” />

<br /><br />

Unlike Java, C++ doesn’t incorporate a debugger into every application. If you need one you have to provide it. Your compiler typically has one.
Just start it up and run your application. Car.cpp:381:runtime_exception:Could not find the brake Police.cpp:123:traffic_observation_exception: Speed too high
Driver.cpp:2131:existential_exception:I am in jail. If you happen to be developing on a system like Linux, then you could use one of many utilities such as electric fence. These are designed to
provide the platform specific capabilities you seem to be looking for, &and; unless I’m mistaken, they tie into GDB. Well, I want this stack trace as a final output for the end user. I am
writing a kind of compiler where I process user input. I have a parser that reads user input and constructs sth called Items or int primitives
</p>

</body>
</html>[/code]

Thanks

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Angry_Black_ManMar 03.2012 — alerts don't understand HTML. they understand text and character entities. the character entity for a line return is:

n

e.g.

alert("testntest")
alert("testnntest")


etc.
Copy linkTweet thisAlerts:
@RodionGorkMar 03.2012 — [CODE]
alert("BlanMla");
[/CODE]


Remember javascript resembles java and C and learn to use literal escape sequences.
Copy linkTweet thisAlerts:
@Angry_Black_ManMar 03.2012 — literal escape sequences.[/QUOTE]

to expound, the backslash is the escape sequence, and the "n" is the character code for a line return. if you type "", you'll see a single backslash in an alert, for instance.

http://zone.ni.com/reference/en-XX/help/371361B-01/lvhowto/backslash_codes_display/
Copy linkTweet thisAlerts:
@tariquwOct 04.2023(updated) — To create a two-line alert message, the newline character n can help. Here's an example: Replace displayDate() in your code with this updated version to display two lines of date information within an alert box. Note, please, that the tag you used is for HTML markup only and won't work within an alert()function. thanks and regards pawan tanwar
×

Success!

Help @jigneshjsoni spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...