Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-05-2010, 08:07 PM   PM User | #1
ukdeveloper
New to the CF scene

 
Join Date: Dec 2010
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
ukdeveloper is an unknown quantity at this point
line breaks in document.write syntax

Hi I currently have this:

var d = new Date()
var theDay = d.getDay()
switch (theDay)
{
case 1:
document.write("On Air Tonight...") <br>
document.write("ALAN POWELL!")
document.write("8pm - 10pm")
document.write("CARL KANE!")
break
case 2:
document.write("On Air Tonight...")
document.write("ALAN POWELL!")
document.write("8pm - 10pm")
document.write("CARL KANE!")
break
case 3:
document.write("On Air Tonight...")
document.write("ALAN POWELL!")
document.write("8pm - 10pm")
document.write("CARL KANE!")
break
case 4:
document.write("On Air Tonight...")
document.write("ALAN POWELL!")
document.write("8pm - 10pm")
document.write("CARL KANE!")
break
case 5:
document.write("On Air Tonight...")
document.write("ALAN POWELL!")
document.write("8pm - 10pm")
document.write("CARL KANE!")
break
case 6:
document.write("On Air Tonight...")
document.write("ALAN POWELL!")
document.write("8pm - 10pm")
document.write("CARL KANE!")
break
case 7:
document.write("On Air Tonight...")
document.write("ALAN POWELL!")
document.write("8pm - 10pm")
document.write("CARL KANE!")
break
default:
document.write("On Air Tonight...")
document.write("ALAN POWELL!")
document.write("8pm - 10pm")
document.write("CARL KANE!")
}

Which obviously outputs the following:

On Air Tonight...ALAN POWELL!8pm - 10pmCARL KANE!

How do i code it so it displays

On Air Tonight...

ALAN POWELL!
8pm - 10pm

CARL KANE!

Also in Firefox, its not displaying ANYTHING... is there anything wrong in the code which FF would throw out?

CSS validation says everything is ok

any help would be fantastic.

Thanks in advance

UKD.
ukdeveloper is offline   Reply With Quote
Old 12-05-2010, 08:15 PM   PM User | #2
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,860
Thanks: 9
Thanked 289 Times in 285 Posts
Dormilich is on a distinguished road
add line breaks: wrap each "line" in a block element or use <br> elements

FF issue: if you call document.write() after the page loaded, it wipes your page clean.

PS. CSS validation doesn’t detect CSS issues created by JavaScript
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Old 12-05-2010, 08:30 PM   PM User | #3
ukdeveloper
New to the CF scene

 
Join Date: Dec 2010
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
ukdeveloper is an unknown quantity at this point
Quote:
Originally Posted by Dormilich View Post
add line breaks: wrap each "line" in a block element or use <br> elements

FF issue: if you call document.write() after the page loaded, it wipes your page clean.

PS. CSS validation doesn’t detect CSS issues created by JavaScript
WOW that was quick..

Thanks so much for the reply.

So how can i get over the firefox issue as this is the only browser that seems to throw up these errors?

Also i did put

document.write("On Air Tonight...") <br>
document.write("ALAN POWELL!") <br>
document.write("8pm - 10pm") <br>
document.write("CARL KANE!") <br>

but FF threw up all kinds of wierdness.

Cheers

UKD
ukdeveloper is offline   Reply With Quote
Old 12-05-2010, 08:44 PM   PM User | #4
DrDOS
Senior Coder

 
Join Date: Sep 2010
Posts: 1,146
Thanks: 10
Thanked 148 Times in 148 Posts
DrDOS is infamous around these parts
Firefox is right, that is incorrect code.
Code:
document.write("On Air Tonight...<br>")
document.write("ALAN POWELL!<br>")
document.write("8pm - 10pm<br>")
document.write("CARL KANE!<br>")
Also if you want the code to be on individual lines in the source use document.writeln, which is document write line.
DrDOS is offline   Reply With Quote
Old 12-05-2010, 08:50 PM   PM User | #5
ukdeveloper
New to the CF scene

 
Join Date: Dec 2010
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
ukdeveloper is an unknown quantity at this point
Quote:
Originally Posted by DrDOS View Post
Firefox is right, that is incorrect code.
Code:
document.write("On Air Tonight...<br>")
document.write("ALAN POWELL!<br>")
document.write("8pm - 10pm<br>")
document.write("CARL KANE!<br>")
Also if you want the code to be on individual lines in the source use document.writeln, which is document write line.
ok so this should work?

document.write("On Air Tonight...")
document.writein
document.writein
document.write("ALAN POWELL!")
document.writein
document.write("8pm - 10pm")
document.writein
document.write("CARL KANE!")

Also how to get around the FF issue that Dormilich mentioned of the page loading ?

UKD
ukdeveloper is offline   Reply With Quote
Old 12-05-2010, 08:50 PM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
document.write() is a very primitive way of outputting data. document.write() statements must be run before the page finishes loading. Any document.write() statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page. So document.write() is at best really only useful to write the original content of your page. It cannot be used to update the content of your page after that page has loaded.


You will find a radio schedule script at http://www.codingforums.com/showthread.php?t=154989 Post #24

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

Last edited by Philip M; 12-05-2010 at 08:55 PM..
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
ukdeveloper (12-05-2010)
Old 12-05-2010, 09:01 PM   PM User | #7
ukdeveloper
New to the CF scene

 
Join Date: Dec 2010
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
ukdeveloper is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
document.write() is a very primitive way of outputting data. document.write() statements must be run before the page finishes loading. Any document.write() statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page. So document.write() is at best really only useful to write the original content of your page. It cannot be used to update the content of your page after that page has loaded.


You will find a radio schedule script at http://www.codingforums.com/showthread.php?t=154989 Post #24

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
Thanks so much for that.

ALthough, how would that be coded to show just whos on that day... not at the particular time?

for instance to display

6-8pm John Smith
8-10pm Jenny Brown

This syntax is great, but completely new to me

UKD
ukdeveloper is offline   Reply With Quote
Old 12-05-2010, 09:33 PM   PM User | #8
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by ukdeveloper View Post
Thanks so much for that.

ALthough, how would that be coded to show just whos on that day... not at the particular time?

for instance to display

6-8pm John Smith
8-10pm Jenny Brown

This syntax is great, but completely new to me

UKD
Sorry, I do not understand. Is not 6-8pm John Smith 8-10pm Jenny Brown showing the particular time? Obviously if you do not want the times to display you simply remove them. But that seems to me to nullify the point of a radio schedule which informs who is on air now. If all you want to do is to list the performers of that day, then a simple list will suffice, but outputing to a <div> rather than with docuemnt.write().

Last edited by Philip M; 12-05-2010 at 09:41 PM..
Philip M is offline   Reply With Quote
Old 12-05-2010, 09:36 PM   PM User | #9
ukdeveloper
New to the CF scene

 
Join Date: Dec 2010
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
ukdeveloper is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
Sorry, I do not understand. Is not 6-8pm John Smith 8-10pm Jenny Brown showing the particular time? Obviously if you do not want the times to display you simply remove them.
Hi,

What i actually need is a display showing who is coming up in the evening not who is on air "right now".

The radio station i am doing this for only broadcast in the evening so on monday i need it to say:

EG MONDAY:
Tonight:

6pm-8pm Johhny Smith
8pm - 10pm Jenny Brown

TUEDAY:
Tonight:

6pm-8pm Bob Green
8-10pm Mike Grey

etc

UKD
ukdeveloper is offline   Reply With Quote
Old 12-06-2010, 11:12 AM   PM User | #10
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
In effect you already have this, but days in Javascript are 0-6. So get the day, and display the appropriate message using the switch statement.

Code:
var d = new Date();  
var theDay = d.getDay();  // days are 0 Sunday -6 Saturday
theDay = 1
switch (theDay) {
case 1:
document.write("On Air Tonight...<br>");
document.write("ALAN POWELL! <br>");
document.write("8pm - 10pm <br>");
document.write("CARL KANE! <br>");
break;
... and so on
}
Philip M is offline   Reply With Quote
Old 12-06-2010, 08:45 PM   PM User | #11
tom_my
New Coder

 
Join Date: Dec 2010
Posts: 13
Thanks: 0
Thanked 1 Time in 1 Post
tom_my is an unknown quantity at this point
And one more advice: document.write isn't good idea for displaying data. If I got you right, you need to show four different lines. Put in your HTML code 4 p tags with id. Then in javascript assign them to vars using document.getElementById and use .innerHTML to put text into them. This way you can style paragraphs as you like by CSS.
tom_my is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:06 AM.


Advertisement
Log in to turn off these ads.