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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    *** HELP *** Text formatting

    Hello,

    I wrote this script (well, not really wrote)

    Code:
    <script>
    <!--
    
    var today_obj=new Date()
    var today_date=today_obj.getDate()
    var tips=new Array()
    var tiptitle='<img src="https://sites.google.com/site/psychally/home/10393545_s%20-%20Copy.jpg"> <b>.... Learn more 
    
    at Psych Wiki</b><br><br>'
    tips[1]='Tip 1 goes here'
    tips[2]='Tip 2 goes here'
    tips[3]='Tip 3 goes here'
    tips[4]='Tip 4 goes here'
    tips[5]='Tip 5 goes here'
    tips[6]='Tip 6'
    tips[7]='Tip 7 goes here'
    tips[8]='Tip 8 goes here'
    tips[9]='Tip 9 goes here'
    tips[10]='Tip 10 goes here'
    tips[11]='Tip 11 goes here'
    tips[12]='Tip 12 goes here'
    tips[13]='Tip 13 goes here'
    tips[14]='Tip 14 goes here'
    tips[15]='Tip 15 goes here'
    tips[16]='Tip 16 goes here'
    tips[17]='Tip 17 goes here'
    tips[18]='Tip 18 goes here'
    tips[19]='Tip 19 goes here'
    tips[20]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-
    
    psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), 
    
    do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include 
    
    delusions of immortality.'
    tips[21]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-
    
    psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), 
    
    do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include 
    
    delusions of immortality.'
    tips[22]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-
    
    psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), 
    
    do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include 
    
    delusions of immortality.'
    tips[23]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-
    
    psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), 
    
    do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include 
    
    delusions of immortality.'
    tips[24]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-
    
    psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), 
    
    do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include 
    
    delusions of immortality.'
    tips[25]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-
    
    psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), 
    
    do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include 
    
    delusions of immortality.'
    tips[26]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-
    
    psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), 
    
    do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include 
    
    delusions of immortality.'
    tips[27]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-
    
    psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), 
    
    do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include 
    
    delusions of immortality.'
    tips[28]='Cotard Syndrome: \nThe Cotard delusion or Cotards syndrome or \nWalking Corpse Syndrome is a rare neuro-
    
    psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), 
    
    do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include 
    
    delusions of immortality.'
    tips[29]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-
    
    psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), 
    
    do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include 
    
    delusions of immortality.'
    tips[30]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-
    
    psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), 
    
    do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include 
    
    delusions of immortality.'
    tips[31]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-
    
    psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), 
    
    do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include 
    
    delusions of immortality.'
    
    document.write(tiptitle)
    document.write(tips[today_date])
    
    
    </script>
    Can someone please tell me how can I format the text that appears on the page from using the script? THANKS
    Last edited by VIPStephan; 12-30-2011 at 11:28 PM. Reason: wrapped code BB tags

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,926
    Thanks
    56
    Thanked 549 Times in 546 Posts
    you are really better off putting your text into a div then using css to style it:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <style>
    #title{
    color:#FF0000;
    }
    #tips{
    color:#00FF00;
    }
    </style>
    </head>
    <body>
    <div id="title"></div>
    <div id="tips"></div>
    <script>
    <!--
    
    var today_obj=new Date()
    var today_date=today_obj.getDate()
    var tips=new Array()
    var tiptitle='<img src="https://sites.google.com/site/psychally/home/10393545_s%20-%20Copy.jpg"> <b>.... Learn more at Psych Wiki</b><br><br>'
    tips[1]='Tip 1 goes here'
    tips[2]='Tip 2 goes here'
    tips[3]='Tip 3 goes here'
    tips[4]='Tip 4 goes here'
    tips[5]='Tip 5 goes here'
    tips[6]='Tip 6'
    tips[7]='Tip 7 goes here'
    tips[8]='Tip 8 goes here'
    tips[9]='Tip 9 goes here'
    tips[10]='Tip 10 goes here'
    tips[11]='Tip 11 goes here'
    tips[12]='Tip 12 goes here'
    tips[13]='Tip 13 goes here'
    tips[14]='Tip 14 goes here'
    tips[15]='Tip 15 goes here'
    tips[16]='Tip 16 goes here'
    tips[17]='Tip 17 goes here'
    tips[18]='Tip 18 goes here'
    tips[19]='Tip 19 goes here'
    tips[20]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[21]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[22]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[23]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[24]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[25]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[26]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[27]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[28]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[29]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[30]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[31]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    
    document.getElementById("title").innerHTML=tiptitle;
    document.getElementById("tips").innerHTML=tips[today_date];
    
    </script>
    </body>
    </html>
    
    or do you mean something else by "formatting"?

  • #3
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks, but I am trying to understand how can I change the tip formatting. Like instead of:

    Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.

    How can I make it look like this:

    Cotard Syndrome:

    The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.

  • #4
    New Coder
    Join Date
    Dec 2011
    Location
    San Francisco, CA
    Posts
    24
    Thanks
    0
    Thanked 5 Times in 5 Posts
    There are at least two ways of doing this.

    You can (1) insert the HTML code directly into the variable definition and use internal CSS style commands. Or you can (2) do the same thing, except using CSS classes.

    Alternative #1

    Code:
    tips[1] = "<b style = 'color:black'>Cotard Syndrome:</b><p style = 'color: red'>The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.</p>";
    Note: the variable is a string wrapped using double quotation marks ("). This means that when you add "style" to your elements, you must use single quotation marks, as I did in the code above.

    Also, I used style = 'color:black' inside the b tag. And color: red in the paragraph tag. Change these to whatever color you want.

    Alternative #2

    Code:
    tips[1] = "<span class = 'header'>Cotard Syndrome:</span><p class = 'ParagraphText'>The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.</p>";
    If you are using this method, you must specify CSS code for "HeaderText" and "ParagraphText" somewhere on your page like so:

    Code:
    ...
    <head>
    <style>
    .HeaderText { font-weight: bold; color: black; }
    .ParagraphText { color: blue; }
    </style>
    </head>
    ....
    This is the preferred method that separates the newbies from the pros!

    Also, as pointed out by the other poster, do not use write function - it's outdated, and no longer used.

    Instead, use "innerHTML" as in:

    Code:
    document.getElementByTagName("body").innerHTML = "put this into body...";
    The method above will not work in all browsers.

    But, if you learn jQuery you can use the cross-browser command:

    Code:
    $("body").html('Replace all text in the body tag with this...');
    Good luck
    Last edited by html-tutorials; 12-29-2011 at 10:30 AM.
    Hi, I'm Greg. I am a web designer.
    I like to share my knowledge with others.
    Web design costs calcuator | jQuery plugin tutorial
    Make cinnamon french toast | bora

  • Users who have thanked html-tutorials for this post:

    DrRaghavSuri (12-29-2011)

  • #5
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks, It worked
    and
    I learned some tricks (or rather basics) about javascript

    Great Job

  • #6
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,926
    Thanks
    56
    Thanked 549 Times in 546 Posts
    document.getElementByTagName("body").innerHTML = "...

    will not work in any browser, ever.

    you can use document.getElementById("body").innerHTML="... (in case you were daring or weird enough to give some element an id of "body") - which works in every browser that I know of

    or document.getElementsByTagName("body") which will return a collection of all the elements with that tag name. And even if, as in the case of "body" there is only one element in the collection, you will still not be able to access it directly, but you will have to access it as if it were an array, like this:
    Code:
    document.getElementsByTagName("body")[0].style.backgroundColor="#FF0000"
    but getting back to the question, if you know that colon is always going to be there, there is a third approach which can save you having to rewrite all your text and insert all those styling tags. Split the string into two, making them an array and then style them according to their position in the array in the final innerHTML.

    A little risky if you're not sure that the colon (or whatever you are using to make the split) will be there, but it makes for lots less coding:

    Code:
    <html>
    <head>
    <style>
    .HeaderText { font-weight: bold; color: black; }
    .ParagraphText { color: blue; }
    </style>
    </head>
    <body>
    <div id="title"></div>
    <div id="tips"></div>
    <script>
    <!--
    
    var today_obj=new Date()
    var today_date=today_obj.getDate()
    var tips=new Array()
    var tiptitle='<img src="https://sites.google.com/site/psychally/home/10393545_s%20-%20Copy.jpg"> <b>.... Learn more at Psych Wiki</b><br><br>'
    tips[1]='Tip 1 goes here'
    tips[2]='Tip 2 goes here'
    tips[3]='Tip 3 goes here'
    tips[4]='Tip 4 goes here'
    tips[5]='Tip 5 goes here'
    tips[6]='Tip 6'
    tips[7]='Tip 7 goes here'
    tips[8]='Tip 8 goes here'
    tips[9]='Tip 9 goes here'
    tips[10]='Tip 10 goes here'
    tips[11]='Tip 11 goes here'
    tips[12]='Tip 12 goes here'
    tips[13]='Tip 13 goes here'
    tips[14]='Tip 14 goes here'
    tips[15]='Tip 15 goes here'
    tips[16]='Tip 16 goes here'
    tips[17]='Tip 17 goes here'
    tips[18]='Tip 18 goes here'
    tips[19]='Tip 19 goes here'
    tips[20]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[21]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[22]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[23]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[24]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[25]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[26]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[27]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[28]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[29]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[30]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    tips[31]='Cotard Syndrome: The Cotard delusion or Cotards syndrome or Walking Corpse Syndrome is a rare neuro-psychiatric disorder in which people hold a delusional belief that they are dead (either figuratively or literally), do not exist, are putrefying, or have lost their blood or internal organs. In rare instances, it can include delusions of immortality.'
    
    document.getElementById("title").innerHTML=tiptitle;
    
    strarray=tips[today_date].split(":", 2)
    document.getElementById("tips").innerHTML="<span class = 'header'>"+strarray[0]+":</span><p class = 'ParagraphText'>"+strarray[1]+"</p>";
    
    </script>
    </body>
    </html>
    Last edited by xelawho; 12-30-2011 at 08:13 AM.

  • Users who have thanked xelawho for this post:

    DrRaghavSuri (12-30-2011)


  •  

    Tags for this Thread

    Posting Permissions

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