Kevin's JavaScript Portfolio Page

These sections are (for now) just a collection of unrelated JavaScript demos. I started working on these back in the summer of 97' when I discovered Nic's Javascript Page gold mine, and I used that to do the first three or four of the demos that follow. Later ones have been done basically when I had the need to put together some JavaScript for some particular purpose. Except where noted (below), these demos all work flawless with Netscape, where the script engine is JavaScript, and with Internet Explorer, where you get Microsoft's JScript™ counterpart... that is, all except for this wee glitch (that only works with IE).


In-Line JavaScript - Quick And Dirty

This demo uses a special form of the html <A href="...">label</A> construct where the "..." part is "script_engine : script code" to directly specify that the script code (any string) is to be passed on to the indicated script_engine, in this case "javascript", for direct execution.

Click on this link to see a message that will pop up because the associated script code invokes the JavaScript function alert() with a familiar built-in string argument.

Using a similar mechanism, click here to see what title is associated with the current document. The same alert() method is invoked using document.title as its argument. This is a very effective way to find out the value of properties associated with your Webpage objects; not like having a real debugger..., but it's better than guessing!

Last updated (this demo): 8/04/1997 17:21


Status & Forms - Passing Around Strings

In this demo you see the simplest kind of <form ...>. There is one input field and a Button object that you can click. The action associated with the button click event simply copies the string currently in the type-in field into the window status line at the bottom of your browser window. If you are using Internet Explorer, you must have the Status Bar option checked [see View.Options] for this line to be visible.

Type in a string:

Every time you Refresh or Reload this page the <form ...> object is reconstructed from scratch so re-clicking the button will simply copy the initial hard-wired prompt phrase into the window status line.

Last updated (this demo): 8/03/1997 21:55


Arithmetic Logic - Time Sentences

This demo takes the actual time of day and turns it into a sentence. There's special help (when needed) for those unfamiliar with 24-hour time, and for children there's an annotation that "rounds off" to the nearest quarter hour, modifying with around if it's two minutes off, or close to for only 1 minute off. The same algorithm is also applied to the minute interval.

Simply Refresh or Reload the page to see how a different time is rendered.

Last updated (this demo): 7/29/1997 12:42


Random Numbers - What's for Breakfast?

This demo picks a phrase from a built-in list of items ("breakfast foods", although the choice is completely arbitrary) and displays the index and name of the item that is chosen randomly [based on Math.random()] when the page is constructed.


random_Breakfast_Item [ ] is


Click the "Chose Again" button to make a different choice. Alternatively you can Refresh or Reload the page (although this appears not to work with IE for a reason that I have not yet determined).

Last updated (this demo): 8/10/1997 16:51


Html TABLEs - Any Calendar

This demo is for playing around with html TABLE constructs in conjunction with a few simple Date object properties. The original idea for this script came from Roberto Favara's home page, but I am bound and determined that I'm going to make it be useable for any calendar year/month you'd like, not just a variation of "show me the current date".

The centered title for this demo shows off a very nifty use for the "number . toString()" function that I found (on Microsoft's JScript™ and VBScript™ page) that will convert a date object into its fully-readable string form.


Select New Day:

Select New Month:

Select New Year:

Simply Refresh or Reload the page to see how a different month/day/year is rendered. (nope! That doesn't work because the Var context is not retained... I'm gonna have to figure out a different way to do this!)

Last updated (this demo): before Thursday, June 18, 1998, 11:17:50 AM


Forms & Buttons - Encode/Decode Strings

This demo is really a little utility tool that I want to write because I need it for Las Vegas!.

It provides a <form ...> which has one input field, a related output field, and a Button object that makes the two correspond. The action associated with the button click encodes the string currently in the type-in field and displays the result in the associated output field. The later (for now) does let you type into it, but doing so has no meaning.


Input string to Encode:
Encoding:

For this demo, the encoding does this: map all odd characters into the letter that comes before them in the alphabet, where odd refers to the ordinal position in the string where the characters appears. All even characters are mapped into the character that follows them, alphabetically. To make sure this all stays within the realm of ASCII (actually, charset=iso8859-1), the mapping leaves the space character alone.

This particular encoding has the useful characteristic that it is reversible by simply offsetting by one. That is, encode a normal word, capture the result, offset that by putting (e.g.) a space in the first character position, and finally re-encode that string. And voilà - you get back the phrase you started with (as long as you ignore the superfluous offset character).

Every time you Refresh or Reload this page the <form ...> object is reconstructed from scratch so if you do this you will lose the phrase that you may have wanted to encode.

Last updated (this demo): before Wednesday, June 17, 1998, 11:00:00 PM


Active Tables - Simple Calculator

In this demo the calculator is an HTML table containing button controls. The buttons themselves are intrinsic INPUT style buttons, not ActiveX controls. JScript code is attached to the OnClick event for these buttons. The display is simply an intrinsic INPUT style text box.

Notice the variable declared at the beginning of the SCRIPT tag, outside of any procedure:

	
<SCRIPT LANGUAGE="JavaScript">
<!-- 
    // Module-level variables
    var FKeyPad = document.Keypad;
    var Accum = 0;                 // Previous number (operand) awaiting operation
    var FlagNewNum = false;        // Flag to indicate a new number (operand) is being entered
    var PendingOp = "";  // Pending operation waiting for completion of second operand
. . .

These are "module-level" variables that persist for as long as the page is loaded. By contrast, variables declared within a procedure cease to exist as soon as the procedure exits. Thus module-level variables can be used to store values that must persist between invocations of a procedure. Module-level variables are also visible to all procedures, and so are useful when multiple procedures need to share values.

JScript Sample: Calculator
 
 
 
 
 


Click here for the full source, context, and credit for this Sample.

If you Refresh or Reload, the calculator variables are reset to zero.

Last updated (this demo): before Thursday, June 18, 1998, 11:17:50 AM


Forms, Select, & Options - Drop-Down List Box

This demo is really a small piece of something that I want to write because I need it for Las Vegas!.

It provides a <form ...> which has a dropdown list which contains a set of pre-determined choices and an initial default. There is also a Button object that reads the value associated with the DropDown list, and does a simple "translation" on it just to show, effectively, that we can have an arbitrary JavaScript function which can do this. What I really want to do with this button is to make it show you the picture, but I haven't fully worked out how to do that. The translation field does (for now) let you type into it, but doing so has no meaning.

The "View" button, above "works" in the sense that it gets you the picture, but it does so in the same window you were in, so you have to use "Back" to get back to where you were. It looks like when you get back, you've still got the one selected you had before, but I'm not sure if the full browser context remains in tact so that's not what I was after for Las Vegas!.

Meanwhile, try Go There to see what happens when I can have the HREF target be a direct call to javascript : view_DropDownSelectionPath(); - Yet you can click on a Direct Path to verify that if I give the link path directly (hard coded) that it does, actually work. But, of course, this has nothing to do with getting the path in conjunction with the DropDown list box.

Every time you Refresh or Reload this page the <form ...> object is reconstructed from scratch but - for a reason that I can't explain - it does not lose its context.

Last updated (this demo): before Wednesday, June 17, 1998, 11:00:00 PM


In-Line Javascript - Link Path Calculation

Like some of the other demos, this one uses a special form of the html <A href="...">label</A> construct where the "..." part is "script_engine : script code" to directly specify that the script code (any string) is to be passed on to the indicated script_engine, in this case "javascript", for direct execution.

Pick a Horoscope and/or find out how well you and your mate are matched...

You:

Your partner:

Select the zodiac sign for you and  
your perspective mate, above, and  
then click on the following button  

to go to eXcite and read about  
how compatible, astrologically  
speaking, these two signs are.  

As an added but unrelated freebie,
you can click any of the signs in the
table to the right and go to eXcite
to read your horoscope for today.

Aries Aries: March 21 - April 19
March 21 - April 19
  Taurus Taurus: April 20 - May 20
April 20 - May 20
  Gemini Gemini: May 21 - June 21
May 21 - June 21
Cancer Cancer: June 22 - July 22
June 22 - July 22
  Leo Leo: July 23 - Aug. 22
July 23 - Aug. 22
  Virgo Virgo: Aug 23 - Sept. 22
Aug 23 - Sept. 22
Libra Libra: Sept. 23 - Oct. 23
Sept. 23 - Oct. 23
  Scorpio Scorpio: Oct. 24 - Nov. 21
Oct. 24 - Nov. 21
  Sagittarius Sagittarius: Nov. 22 - Dec. 21
Nov. 22 - Dec. 21
Capricorn Capricorn: Dec. 22 - Jan. 19
Dec. 22 - Jan. 19
  Aquarius Aquarius: Jan. 20 - Feb. 18
Jan. 20 - Feb. 18
  Pisces Pisces: Feb. 19 - March 20
Feb. 19 - March 20
 

GoTo the eXcite Home Page and pick out a "Horoscope" ...


As of 8/Jan/2002 11:32 I've discovered that the "What are the chances?" mechanism, above, no longer works. And my attempts to rework it as per eXcite's new scheme have been foiled, most likely (I suspect) because of all the uncertainty and constantly-changing turmoil wrt the @home folks (who had gone out of business but who are apparently making a come-back). Today they are still on-line (somewhat) but the site is too unreliable for me to continue trying to make this work (and it just doesn't seem worth it).

Last updated (this demo): 8/Jan/2002 15:44



Return to:     Kevin Pammett's résumé     or     the Pammett Family The Pammett Family Home (Groton) HOME Page Home page in Groton...
Staying current... is a constant challenge...
You are visitor number since July 27, 1997, the day I first went public with these demos.

Last updated (anything on this page): January 8, 2002 (8/Jan/2002 16:55)