/    Sign up×
Community /Pin to ProfileBookmark

Adding <br> in javascript

Can’t seem to find something that works here but I want to add a simple br inside the following code to separate the time and date on 2 different lines. Tnx.

[CODE]<head>
<meta charset=”utf-8″>
<title>Untitled Document</title>
<script type=”text/javascript”>
function display_c(){
var refresh=1000; // Refresh rate in milli seconds
mytime=setTimeout(‘display_ct()’,refresh)
}

function display_ct() {
var strcount
var x = new Date()
var x1=x.getMonth()+1 + “/” + x.getDate() + “/” + x.getFullYear();
x1 = x1 + ” – ” + x.getHours( )+ “:” + (x.getMinutes()<10?’0′:”) + x.getMinutes() + “:” + (x.getSeconds()<10?’0′:”) + x.getSeconds();
document.getElementById(‘ct’).innerHTML = x1;
tt=display_c();
document.getElementById(‘ct’).style.fontSize=’48px’;
document.getElementById(‘ct’).style.color=’#ffffff’;
document.getElementById(‘ct’).innerHTML = x2;
}

</script>
</head>

<body bgcolor=”#000000″ onload=display_ct();>
<br><br><br><br><br><p align=”center”><span id=’ct’ ></span></p>
<br><p align=”center”><span id=’ct’ ></span>
</body>[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Host_CapitolMay 09.2016 — Like this?
&lt;head&gt;
&lt;meta charset="utf-8"&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;script type="text/javascript"&gt;
function display_c(){
var refresh=1000; // Refresh rate in milli seconds
mytime=setTimeout('display_ct()',refresh)
}

function display_ct() {
var strcount
var x = new Date()
var x1=x.getMonth()+1 + "/" + x.getDate() + "/" + x.getFullYear();
x1 = x1 + "&lt;br&gt;" + x.getHours( )+ ":" + (x.getMinutes()&lt;10?'0':'') + x.getMinutes() + ":" + (x.getSeconds()&lt;10?'0':'') + x.getSeconds();
document.getElementById('ct').innerHTML = x1;
tt=display_c();
document.getElementById('ct').style.fontSize='48px';
document.getElementById('ct').style.color='#ffffff';
document.getElementById('ct').innerHTML = x2;
}

&lt;/script&gt;
&lt;/head&gt;

&lt;body bgcolor="#000000" onload=display_ct();&gt;
&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;p align="center"&gt;&lt;span id='ct' &gt;&lt;/span&gt;&lt;/p&gt;
&lt;br&gt;&lt;p align="center"&gt;&lt;span id='ct' &gt;&lt;/span&gt;
&lt;/body&gt;
Copy linkTweet thisAlerts:
@ervybabyauthorMay 09.2016 — Thank you. Dunno why it didn't work previously.
Copy linkTweet thisAlerts:
@rootMay 10.2016 — When using JavaScript for time, you don't use it how you have, thats something like 30 years out of date.

To get the time, for example you would
x= new Date();
x1 = d.toUTCString().slice(17,25); // format 00:00:00


and to update, you use a setInterval() function, set it once, calling setTimeout will introduce a margin of error over a long period of time from true time.

So... this bitfunction display_c(){
var refresh=1000; // Refresh rate in milli seconds
mytime=setTimeout('display_ct()',refresh)
}
becomes st = setInterval("display_ct()",1000); because the <i>
</i>function display_c(){
...
part of the script is now defunct, so your line x1 = x1 + "&lt;br&gt;" + x.getHours( )+ ":" + (x.getMinutes()&lt;10?'0':'') + x.getMinutes() + ":" + (x.getSeconds()&lt;10?'0':'') + x.getSeconds(); is not needed as it is replaced by <i>
</i>x1 = x.toUTCString().slice(17,25); // format 00:00:00


Much easier because it is already a formatted string.
×

Success!

Help @ervybaby 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...