Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format color on a variable 1

Status
Not open for further replies.

DRowland

Programmer
May 23, 2001
232
US
I am new working on javascript, and have a problem that is probably very simple to someone with experience.
I have searched previous entries, and tried all I found, with no luck.
What I want to do, is change the color of one line of a variable.
Below is my script.
_____________________________
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()
var dn="AM"
var greet = "<i>Good Morning!</i> "
if (hours>=12){
dn="PM"
greet.fontcolor = '#FF0080"
greet = "<i>Good Afternoon! </i>"}
if (hours>=18){
greet = "<i>Good Evening! </i>"}
if (hours>12){
hours=hours-12
_______________________________
What I want to do is make the "Good Morning" one color,
"Good Afternoon" another, and "good evening a third. So far, nothing has worked, including the "greet.fontcolor...." line shown.
Any help is welcome.
Thanks
Dick



Dick

|========================|
I sure wish there was a way
to receive the best teaching, [smarty]
without having to go through
some of the worst experiences![ponder]
|========================|
 
Instead of
Code:
greet.fontcolor = '#FF0080";
try
Code:
greet.fontcolor('#FF0080');

Also, you seem to be the victim of mismatched quotes. Is that a typo?

--Chessbot
 
Hey Chessbot.. Thanks for the quick response.
Yes the mis=match was a typ-o.
I tried a cut/n/paste of your code, and it didn't work either. It that code is known to work elsewhere, perhaps there is something about my machine that I am not aware of.

Dick

|========================|
I sure wish there was a way
to receive the best teaching, [smarty]
without having to go through
some of the worst experiences![ponder]
|========================|
 
Click here. Does the bottom string show up red?

What browser are you using?

--Chessbot
 
The last line was red, I am using IE6.


Dick

|========================|
I sure wish there was a way
to receive the best teaching, [smarty]
without having to go through
some of the worst experiences![ponder]
|========================|
 
Does this script work for you?
Code:
<html>
<head>
<title>Date</title>
</head>
<body>
<script type="text/javascript">
<!--

var mydate = new Date();
var hours = mydate.getHours();
var minutes = mydate.getMinutes();
var seconds = mydate.getSeconds();
var dn="AM";
var greet = "Good Morning!";

if (hours >= 12)
{
  dn="PM"
  greet.fontcolor('#FF0080');
  greet = "Good Afternoon!";
}
if (hours >= 18)
{
  greet = "Good Evening!";
}

if (hours > 12)
{
  hours -= 12;
}

greet.italics();
document.writeln(greet);

// -->
</script>
</body>
</html>

--Chessbot
 
Nope, That didn't work either.

Dick

|========================|
I sure wish there was a way
to receive the best teaching, [smarty]
without having to go through
some of the worst experiences![ponder]
|========================|
 
What time does your system have? Would it trigger hours>=12? Try hardcoding hours as 20 or something for testing purposes.

--Chessbot
 
Is there a way to do a cut/n/paste without all the language changing on the paste?


Dick

|========================|
I sure wish there was a way
to receive the best teaching, [smarty]
without having to go through
some of the worst experiences![ponder]
|========================|
 
On the code sent earlier, I just inserted the one changed line, and got an error code, no printing at all.


Dick

|========================|
I sure wish there was a way
to receive the best teaching, [smarty]
without having to go through
some of the worst experiences![ponder]
|========================|
 
Copy the whole code into a new file and see if it works. Leave it as is.

--Chessbot
 
I tried that.
All the <'s and >'s etc. were changed, and the who thing was one big paragraph.

Dick

|========================|
I sure wish there was a way
to receive the best teaching, [smarty]
without having to go through
some of the worst experiences![ponder]
|========================|
 
I'm using Front page. Let me try moving it to notepad first, then to FP and see what happens. I am using the HTML editor for FP.

Dick

|========================|
I sure wish there was a way
to receive the best teaching, [smarty]
without having to go through
some of the worst experiences![ponder]
|========================|
 
Don't use frontpage; it WON'T work! Use notepad and save as .html.

--Chessbot
 
Ok... I just did it with notepad, and ran it on Ie, with no changes in color, and tested it with different times.
HMMMMM


Dick

|========================|
I sure wish there was a way
to receive the best teaching, [smarty]
without having to go through
some of the worst experiences![ponder]
|========================|
 
I also wondered if there is a way to create custom controls such as the bold, italic, etc controls. That way I could just enter a <XXX> command in the same manner as the <b> and have it done. Has anyone ever heard of a way to create such things?

Dick

|========================|
I sure wish there was a way
to receive the best teaching, [smarty]
without having to go through
some of the worst experiences![ponder]
|========================|
 
Open it, hit "view source", and post the code. Let's see if anything got changed somewhere.

--Chessbot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top