...

View Full Version : *** HELP *** Text formatting



DrRaghavSuri
12-28-2011, 02:57 PM
Hello,

I wrote this script (well, not really wrote)


<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

xelawho
12-29-2011, 12:41 AM
you are really better off putting your text into a div then using css to style it:



<!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"?

DrRaghavSuri
12-29-2011, 01:07 AM
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.

html-tutorials
12-29-2011, 10:20 AM
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


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


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:



...
<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:


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:


$("body").html('Replace all text in the body tag with this...');

Good luck ;)

DrRaghavSuri
12-29-2011, 11:47 AM
Thanks, It worked :)
and
I learned some tricks (or rather basics) about javascript

Great Job

xelawho
12-30-2011, 07:44 AM
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:

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:



<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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum