Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,436
    Thanks
    13
    Thanked 360 Times in 356 Posts
    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
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,427
    Thanks
    17
    Thanked 272 Times in 272 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,239
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    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 09:55 PM.

  • Users who have thanked Philip M for this post:

    ukdeveloper (12-05-2010)

  • #7
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,239
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    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 10:41 PM.

  • #9
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #10
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,239
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    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
    }

  • #11
    New Coder
    Join Date
    Dec 2010
    Posts
    13
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •