Monday, February 2, 2015

A beautiful set of ball linking with each other on near contact.

Random Maze Generator Source Code

Javascript slide show

<SCRIPT>var myPix = new Array("images/pathfinder.gif", "images/surveyor.gif", "images/surveyor98.gif");
var thisPic = 0;
function processPrevious() {
     if (document.images && thisPic > 0) {
          thisPic--;
          document.myPicture.src = myPix[thisPic];
     }
}
function processNext() {
     if (document.images && thisPic < 2) {
          thisPic++;
          document.myPicture.src = myPix[thisPic];
     }
}
</SCRIPT>
<IMG SRC="images/pathfinder.gif" NAME="myPicture">
<HREF="javascript:processPrevious()">Previous</A>
<
HREF="javascript:processNext()">Next</A>

Javascript function determines whether a Credit Card number is "valid"

// The function determines whether a Credit Card number is "valid"
// Please note that a "valid" Credit Card number is not essentially a Credit Card in "Good Standing"
function isValidCreditCard(number) {
     if (number.indexOf("-")) {
          cc = number.split("-");
          number = "";
          for (var i = 0; i < cc.length; i++) number += cc[i];
     }
     // Another Version of what was performed above using String & Array Methods
     if (number.
indexOf(" ")) {
          cc = number.
split(" ");
          number = cc.
join("");
     }
     // OR using RegExp we can combine the above two
     
//  number = number.replace(/-|\s/g, "");
     /**********************************************/
     if (number.length > 19) return (false);
     sum = 0; mul = 1; l = number.length;
     for (i = 0; i < l; i++) {
          digit = number.substring(l - i - 1, l - i);
          tproduct = parseInt(digit, 10) * mul;
          if (tproduct >= 10) sum += (tproduct % 10) + 1;
          else sum += tproduct;
          if (mul == 1) mul++;
          else mul--;
     }

     if ((sum % 10) == 0) return (true);
     else return (false);
}

Javascript Jump list Choose A Page and Jump:


<FORM>selectedIndex is the "Index number" that the user "chose"
notice that the <SELECT> tag has a bunch of options -- hence an Array of Options
the Options all have a value & that value is a URL
location.href = URL is where we will end up going to
<SELECT onChange="location.href=options[selectedIndex].value">
     <OPTION VALUE="index.htm">Select a Page</OPTION>
     <OPTION VALUE="crossword.htm">Crossword Puzzle</OPTION>
     <OPTION VALUE="email.htm">E-mail Address Check</OPTION>
     <OPTION VALUE="banner1.htm">Random Banner</OPTION>
     <OPTION VALUE="quotes.htm">Random Quotes</OPTION>
     <OPTION VALUE="rollover.htm">Rollover Example</OPTION>
</SELECT>
</FORM>

Javascript Clock Military or Civilian Time?

<SCRIPT>

var now;

function showMilitaryTime() {
     if (document.theForm.showMilitary[0].checked) {
          return true;
     }
     return false;
}

function showTheHours(theHour) {
     if (showMilitaryTime() || (theHour > 0 && theHour < 13)) {
          return (theHour);
     }
     if (theHour == 0) {
          return (12);
     }
     return (theHour - 12);
}

function showZeroFilled(inValue) {
     if (inValue > 9) {
          return ":" + inValue;
     }
     return ":0" + inValue;
}

function showAmPm() {
     if (showMilitaryTime()) {
          return ("");
     }
     if (now.getHours() < 12) {
          return (" am");
     }
     return (" pm");
}

function showTheTime() {
     now = new Date();
     document.theForm.showTime.value =
     showTheHours(now.getHours()) +
     
showZeroFilled(now.getMinutes()) +
     
showZeroFilled(now.getSeconds()) +
     
showAmPm();
     setTimeout("showTheTime()", 1000);
}
</SCRIPT>
<BODY onLoad="showTheTime();">

<FORM NAME="theForm">
     <INPUT TYPE="TEXT" NAME="showTime">
     Display Military Time?
     <INPUT TYPE="RADIO" NAME="showMilitaryCHECKED>Yes
     <INPUT TYPE="RADIO" NAME="showMilitary">No
</FORM>

Javascript Calculating the sum of the digits

<SCRIPT>
function sumDigits(num) {
     var i, sum = 0;                  // can declare two variables at once
     for (i = 1; i <= num; i++) {
             sum += i;              // add each number to sum (ie, 1 + 2 + ...+ num)
     }
     // Display result
     alert("The sum of the digits from 1 to "+ num + " is:\n\n\t " + sum);
}
</SCRIPT>
<BODY>
Looping Functions - Calculate the sum of the digits.
<FORM NAME="SumNums">
     The sum of the digits from 1 to:
     <INPUT TYPE="text" NAME="charNum">
     <INPUT TYPE="button" VALUE="Calculate"
       onClick="sumDigits(SumNums.charNum.value)">
</FORM>