/introduction/newsletter_archive/goodiestogo/article.php/3476541/Goodies-to-Go-tmbrJanuary-6-2003---Newsletter-214.htm Goodies to Go (tm)<br> January 6, 2003-- Newsletter #214

Goodies to Go (tm)
January 6, 2003-- Newsletter #214

By Vince Barnes

Goodies to Go (tm)
January 6, 2003--Newsletter #214

This newsletter is part of the internet.com network.

Featured this week:

* Goodies Thoughts - A JS New Year.
* Q & A Goodies
* News Goodies
* Feedback Goodies  
* And Remember This...



Goodies Announcement

Just in case you missed it before, the new Beyond HTML Goodies book is now available!


Go beyond the basics and learn how the pros add and use dynamic HTML features and advanced JavaScript techniques. Beyond HTML Goodies demonstrates dozens of new and different features readers can add to their existing Web pages using HTML and JavaScript. The book starts with simple text and image tips, such as adding a clock to a Web page or causing text to appear when the mouse moves over an image. It gradually builds to more complex tricks, including manipulating forms or working with cookies behind the scenes. Throughout the book, readers enjoy Joe's snappy style and "to the point" discussion of each "goody" in the book.





Goodies Thoughts - A JS NEw Year.

Karl Gustav Jung coined the term "synchronicity" to refer to those events that, while on the surface appear disconnected, have something in common and occur close to each other in time. For example, you get a new computer and you happen notice that its BIOS comes from Phoenix Technologies, you turn it on and check your email only to find an advertisement for Phoenix University's on-line campus. Then the phone rings and it's your buddy calling you from Phoenix, Arizona, where his flight was diverted because of a storm in your area. That's synchronicity. When it happens around me, I say "Huh!"

In last week's newsletter there was a Q&A piece about getting a date in JavaScript (see http://www.htmlgoodies.com/letters/213.html). The question wondered why the month always turned out to be one less than is should be, while the day and the year were correct. Wally Bamberger had responded (thanks Wally) with a solution to the problem. During the week, one of my friends asked me how he could add the current date to the middle of a passage in his web page. Then one of the guys at Jupiter Media (our company) wondered if we use JavaScript to obtain the correct year for the copyright notice on our web pages. Meanwhile, several people wrote back to our feedback email address concerning the Q&A piece and offering further explanations. I say "Huh!" Perhaps it's just because of the new year and; perhaps it's coincidence or; perhaps it's synchronicity -- whichever it is, it clearly deserves a little further attention!

Here's the code that was in the original question:
RightNow = new Date();
document.write("Today's date is " + RightNow.getMonth()+ "-")
document.write(" "+ RightNow.getDate() + "-" + RightNow.getFullYear() + ".")
document.write("<.br><.br>You entered this Web Page at exactly: " + RightNow.getHours() + " hours")
document.write(" "+ RightNow.getMinutes() + " minutes and " + RightNow.getSeconds() + " seconds")
(I've added a couple of line breaks to make the result a little easier to read. Also, note the periods after each "<" -- see the note in the Q&A section below.)

The problem was that the month was turning out to be one less than expected; for example, 3 would be returned in April. Wally indicated that he had come across this before, and provided some code to compensate. The writers who sent in feedback all had another part of the puzzle, but it seemed like the whole thing needed to be explained.

First, no, it's not a bug! Second, JavaScript starts all indices at zero, not one. That's correct, but doesn't explain why the month comes out less than we might expect, but the year and day (and all the time elements) come out as we expect. To explain it, let's take a closer look at the code.

The Date() constructor creates an instance of a date object, based on the current date and time. In this case we are creating a new instance called RightNow. In the document.write statements, several methods of the date object are used to return elements of the date and time. This (alphabetical) list describes them and what they do for us (I've included a couple that aren't used in the example, but provide some more useful stuff):

getDate returns the day of the month from the object. Values are between 1 and 31.
getDay returns the day of the week. Values are between 0 and 6.
getFullYear returns the full year (that is, four digit).
getHours returns the hours. Values are between 0 (midnight) and 23 (11 pm).
getMilliseconds returns the milliseconds.
getMinutes returns the minutes. Values are between 0 and 59.
getMonth returns the month. Values are between 0 (January) and 11 (December).
getSeconds returns the seconds. Values are between 0 and 59.
getTime just to throw you off.... this returns the date expressed as the number of milliseconds past midnight (GMT) on January 1, 1970.
getTimezoneOffset returns the number of minutes difference between GMT and the local time zone (they used minutes because some time zones are offset by a half hour.)

So why do some start at zero, and some at one? If you look, you'll see that those that (unexpectedly) start at zero, can also be expressed another way. For example, the day of the week could be Sunday, Monday, etc. The month could be a number or it could be January, February, etc. The hour could be 22 or 10pm.

As was pointed out, in JavaScript, indices start at zero. Suppose we had an array named "months" with twelve elements defined, containing the names of the months of the year (for more about arrays, see the JS tutorial at http://www.htmlgoodies.com/primers/jsp/hgjsp_26.html) Now try this bit of code:
document.write("The current month is " + months[RightNow.getMonth()] + ".")
Since it returns values starting at zero, getMonth is perfect for use as the index into our array of month names! Now we see the method behind the madness (all puns are, of course, intended!) Exactly the same applies to the days of the week and to the hours of the day. Minutes and seconds start at zero because those are the possible values for minutes and seconds! The other numbers are returned as the numbers that they are - they're not valuable as an index into some other array.

Great! So why did I try to throw you off with that getTime thing? What use is it? It's a timing thing. You can use it to obtain the arithmetic difference between one moment in time and another. And the other one -- getTimezoneOffset -- well, think creatively and you'll come up with a use for it!! It is interesting to note, however, that getTimezoneOffset is a method of the Date object, but doesn't actually reference the Date object. Usually, something like that would be an independent function, but not this bad boy!

Ahh, how joyous is JS!!

Have a JS new year!!

Thanks for Reading!
- Vince Barnes



Q & A Goodies

Questions are taken from submissions to our Community Mentors. You can ask a Mentor a question by going to http://www.htmlgoodies.com/mentors/.

Q.  My website is done in tables, and I have one Cell on the top, three Cells in the middle and one cell on the bottom. I want to make it so the in the middle 3 cells, all the text is forced to the top. I tried td align=top but that didn't work.

A. Change the align to valign and code it like so: td valign="top"

Q. How do I detect a flash plug-in and redirect the browser to a new URL?

. Flash kit had a couple ways. I don't know which you need, so here is the search results page: http://www.flashkit.com/search.php?term=detect+plug+in&cat=tutorials&version=--&per=10&field=Description&orderby=Rating&andor=or&page=1&submit=Submit

Q. I am constantly creating files (pdf or word) files that I need to show to many co-workers. Instead of having to email everyone everytime I finish a file, I would like to upload the file to my server and have them view the list of files online and download the ones they want. These files need to be password protected as different people in different departments should only see files pertaining to them. Here was my idea, create a bunch of password protected folders on a server - one for each department, and I will upload the file to any folder that should be allowed to view these files. Two questions: 1) I put the files in a folder, but when I try to view the folder in a browser it tells me I don't have permission to access this folder (I assume because I never created an index file). How can I set it up that I should be able to view a list of files that are in the folder? 2) how can I create a page that will allow me to upload files to folders using a browser?

. I believe you are correct in that you do not have an INDEX file for the server to show when you try to access the folder. You could create an INDEX file with the links to the documents for downloading. I am assuming that you have already password protected the folder? An even easier way would be to use a password log in feature for your pages. The application would allow users to sign up themselves and you would control which group the user should be in and only the documents or files you allow each group or person to view. There is a nice web application called ASPLogin. It has to run on a server that supports ASP. For example, to make a document available to all users in a group called 'management', members of a group called 'administrators' and a user called 'fred' (who may or may not be in either of the groups), you would add the following code to the top of the document:
<%@ LANGUAGE=VBScript %>
Set asplObj=Server.CreateObject("ASPL.Login")
Set asplObj=Nothing
Any other group or person trying to see that document will not be allowed to see it. It is a pretty slick application You can take a look here: http://www.asplogin.com
To create a page to allow you to upload documents would call for some scripting. This all depends on what type of server you site is hosted on. If it is a Windows server then it will support Active Server Pages (ASP).

Q. I saw on a website once where there were dainty little buttons that did the equivalent of a browser's back, refresh, and forward buttons. I found the JavaScript code for that on Html Goodies, but is there no way to apply this event to a hotspot on an image? With the script on the website, I'm under the impression it is written to create a standard form button with the back (etc.) abilities. I have an image on which I want to select a hotspot which will act as a back (etc.) button. Help?

A. What you are looking for is called an image map. Here is a link to a tutorial on the HTMLGoodies web site: http://htmlgoodies.earthweb.com/tutors/im.html
It is best to have a tool to assist you in defining the hotspots of an image so check your Dreamweaver documentation for references to image maps. If you find this to be lacking, there is an excellent piece of shareware called MapEdit available from boutell.com at: http://www.boutell.com/mapedit  At $10 it's a bargain.

Q. Is there something you could use so that when the mouse moves over a link it would look like a regular text, meaning that the mouse-pointer would turn into an I shape instead of a hand?

A. This tutorial will explain it: http://www.htmlgoodies.com/beyond/css_cursors.html
Something to be aware of is the effect can vary between browsers. Test it at least in the recent IE and Netscape to make sure nothing is screwed up.





News Goodies

Investors Slam Door on Hotels.com
[January 6, 2003] Wall Street sends the stock down 25% after the booking service says 4Q revenues and earnings won't meet expectations; travel, online and off, remains a sector in disarray.

Click here to read the article


VeriSign Re-launches Network Solutions Brand
[January 6, 2003] Almost three years after acquiring Northern Virginia-based domain registrar and renaming its VeriSign Global Registry Services, Network Solutions lives again.

Click here to read the article


Palm Licenses New OS to Korean Firm
[January 6, 2003] With the help of Motorola's old wireless ReFLEX network, the handheld computer maker's software spin-off adds to its list of OS 5 licensees.

Click here to read the article


Apple Polishes Up for Macworld 2003
[January 3, 2003] UPDATE: Woz is back and Jobs has big news as the Mac faithful assemble in San Francisco for Apple's annual love-fest and rumor mill.

Click here to read the article



Kodak Ready to Bridge Film and Digital?
[January 3, 2003] With CES 2003 around the corner, one analyst thinks Kodak is being underestimated, largely due to a new technology that may bridge the gap between film and digital photography.

Click here to read the article



Violence Breaks out in Los Angeles Cyber Cafes
[January 3, 2003] Popular combat simulator games are seen as catalysts for street brawls that have Los Angeles police and city council members scrambling for solutions.

Click here to read the article



Sun Scraps MySun E-mail Service
[January 3, 2003] Sun Microsystems joins the trend among big-name companies to discontinue free e-mail services.

Click here to read the article



New Dolby Tech Sounds Good to ADI Chipsets
[January 2, 2003] The sound specialists at Dolby Labs put their Virtual Speaker technology in chipsets for use in TVs, stereos, video-game consoles, in-car entertainment systems and DVDs.

Click here to read the article




E-Comm Industry Gets a 'C' Despite Record Spending
[December 31, 2002] Despite the fact that consumers spent record amounts of money doing their holiday shopping online this year, online retailers only earned a 'C' rating for customer satisfaction.

Click here to read the article







Feedback Goodies

Did you ever wish your newsletter was an easy two way communications medium? Ploof! It now is!
If you would like to comment on the newsletter or expand/improve on something you have seen in here, you can now send your input to:


We already receive a lot of email every day. This address will help us sort out those relating specifically to this newsletter from all the rest. When you send email to this address it may wind up being included in this section of the newsletter, to be shared with your fellow readers. Please don't send your questions to this address. They should be sent to our mentors: see http://www.htmlgoodies.com/mentors/

According to the stats, about four hundred of you actually went to take a look at the slug site (http://www.UpperLowerbury.com/slugs) and about a third of that number also took a look at the site's home page. Thanks for visiting! Thanks also for the notes some of you sent me -- you know who you are and what you said <g>! What's life without a little humor? Thanks also to Mary S who sent me a slug with a Swedish heritage. What a cutie it is too!! Did you find that one in Upper Lowerbury, Mary?



And Remember This . . .

On this day in...

1919: President Theodore Roosevelt dies
The 26th President of the United States died at his estate, "Sagamore Hill" in Long Island, NY, on this day in 1919. In 1898 Roosevelt was assistant secretary to the Navy and was a strong proponent of going to war with Spain. When the Spanish-American war began, he formed a volunteer cavalry known as the "Rough Riders", who are famous for their part in the victory at the Battle of San Juan Hill in Cuba. With his military fame he easily won election to the post of Governor of New York in 1898 and became Vice-President of the US in 1900. When William McKinley was assassinated in 1901 the 43 year old Roosevelt became the youngest president ever to assume the office. He was elected to a second term in 1904. Roosevelt insisted on a strong Navy, independence for Panama and the construction of the Panama Canal. He created the first National Parks and National Monuments. He negotiated the peace that ended the Russian-Japanese war, for which he was awarded the Nobel Peace prize. In 1902, Roosevelt went on a hunting trip in Mississippi and made history by not shooting a bear cub. Washington Post political cartoonist Clifford Berryman drew a sketch called "Drawing the Line in Mississippi," and the cartoon inspired a couple of shopkeepers in New York to make a little bear cub toy which they called "Teddy's bear". At the same time, Margarete Steiff in Germany created her first Bear toys based on drawings of bears her nephew made at a local zoo. Teddy Bears are still popular today. At his death, Roosevelt was 60 years old.

1412: Joan of Arc (Jeanne D'Arc) was born
The Maid of Orleans, the French heroine who liberated the city of Orleans from the English was born on this day in 1412. After leading French armies to many victories, and claiming that she was spoken to directly by God, which caused great concern among Church leaders, she was burned at the stake as a witch. She has since been canonized a Roman Catholic saint.


Thanks for reading Goodies to Go!


Archive Home Page.

  • Web Development Newsletter Signup

    Invalid email
    You have successfuly registered to our newsletter.
Thanks for your registration, follow us on our social networks to keep up-to-date