<< Previous Topic | Next Topic >>  

Quick q on the "Good Morning" script

February 8 2005 at 6:14 AM
Mac (the other one)  (no login)

 
I've noticed that the "Good Morning/Afternoon/Evening" script when it reads 'nbabauth' from the N54 cookie returns + signs in place of spaces. This means in my case for example that instead of displaying:

Good Morning Mac (the other one)

It says:

Good Morning Mac+(the+other+one)

Is there some quick tweak that could catch and fix this? I can try to play with it but I have limited free time so thought it may be easier to just post and ask if anyone may already have an idea...

Here is the existing code snippet:


<SCRIPT language="JavaScript">
<!--
datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();
if (thehour > 18) display = "Evening";
else if (thehour >12) display = "Afternoon";
else display = "Morning";
var yourname=ReadCookie("nbabauth");
if ((yourname=="") || (yourname=="Anonymous")){thisname="Guest"}
else {thisname=yourname};
document.write("<b>Good " + display + " " + thisname + "</b></font>");
// -->
</script>

Peace, -Mac (the other one)

 
 Respond to this message   
AuthorReply

(Premier Login seattlex19)

and a quick ps...

February 8 2005, 8:57 AM 

... this has nothing to do with the above question, but since it is regarding the same script, I thought I would add this comment:

I've noticed that the current script is clearly intended to say "Morning" until Noon, "Afternoon" from Noon to 6, and "Evening" after 6, however, using the greater than actually has caused this to lag by one hour, so in fact it is still saying "Good Morning" from Noon to 1pm, and "Afternoon" until 7pm.

This can easily be rectified by just changing the values > 18 and >12 to > 17 and >11.

Just thought I'd mention it


 
 Respond to this message   

(Premier Login seattlex19)

D'oh! I just did it myself...

February 8 2005, 9:44 AM 

... well, as it turns out, I fixed it myself :)

Hacked a code snippet I grabbed off the net to suit the function, and inserted it.

Here is the solution. Replace the original code section above with this:

<SCRIPT language="JavaScript">
<!--
function greplace(string,text,by) {
var striLength = string.length, txtiLength = text.length;
if ((striLength == 0) || (txtiLength == 0)) return string;
var iei = string.indexOf(text);
if ((!iei) && (text != string.substring(0,txtiLength))) return string;
if (iei == -1) return string;
var newstr = string.substring(0,iei) + by;
if (iei+txtiLength < striLength)
newstr += greplace(string.substring(iei+txtiLength,striLength),text,by);
return newstr;
}
datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();
if (thehour > 17) display = "Evening";
else if (thehour >11) display = "Afternoon";
else display = "Morning";
var firstname=ReadCookie("nbabauth");
var yourname=greplace(firstname,'+',' ');
if ((yourname=="") || (yourname=="Anonymous")){thisname="Guest"}
else {thisname=yourname};
document.write("<b>Good " + display + " " + thisname + "</b></font>");
// -->
</script>

... and from then on, you will be greeting your users, sans plus signs :)

Peace, -Mac (the other one)

 
 Respond to this message   

(Login blackkats4)

Re: D'oh! I just did it myself...

February 8 2005, 10:55 AM 

I use a bit different code for that and have had no problems. some of my posters are overseas and they tell me that the greeting is in their time zone.

here is the code i have been using for about 2 years.

you can change the color and font about half way down.

You will notice that mine is set fot the cookies function in the first part..
Instead of the greplace function

<!--
function ReadCookie(cookieName){
var theCookie=""+document.cookie;
var ind=theCookie.indexOf(cookieName);
if (ind==-1 || cookieName=="") return "";
var ind1=theCookie.indexOf(';',ind);
if (ind1==-1) ind1=theCookie.length;
return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
var today = new Date();
expiry = new Date(today.getTime() + 6*60*24*60*60*1000);
function SetCookie (name, value){
document.cookie=name + "=" + escape (value) + "; expires=" + expiry.toGMTString();
}
// -->
</script></div>

<center><font face="Helvetica,Arial" size="2" color="#FF00ff"><b>
<script>
<!--
datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();
if (thehour > 18) displayEvent = "Evening";
else if (thehour >12) displayEvent = "Afternoon";
else displayEvent = "Morning";
var yourname=ReadCookie("nbabauth")
if ((yourname=="") || (yourname=="Anonymous")){yourname="Guest"}
var greeting = ("Good " + displayEvent + " " + yourname + "")
document.write("<b>"+greeting+"</b>");
// -->
</script>


Kitty, KD, Blackkats4, Cindy
East Texas, 50 miles north of Houston
Ducks and Geese

 
 Respond to this message   
Current Topic - Quick q on the "Good Morning" script
  << Previous Topic | Next Topic >>  
Find more forums on Personal Web PagesCreate your own forum at Network54
 Copyright © 1999-2009 Network54. All rights reserved.   Terms of Use   Privacy Statement