dkFlyer

Adding JavaScript

For an example of a JavaScript, click here, here, here, here, here or here.

This is the JavaScript for 'htmlasc.htm' (Building an ASCII Chart):
(01)<SCRIPT LANGUAGE="JavaScript">
(02)<!--
(03)var font1 = "Symbol"
(04)document.write ('<CENTER><TABLE BORDER=4 WIDTH=90%><TR>'
(05) + '<TD ALIGN=CENTER>Char</TD>'
(06) + '<TD ALIGN=CENTER>Normal</TD>'
(07) + '<TD ALIGN=CENTER>'+font1+'</TD>'
(08) + '</TR>');
(09)document.write ('<TR>'
(10) + '<TD ALIGN=CENTER>#32</TD>'
(11) + '<TD ALIGN=CENTER>(Space)</TD>'
(12) + '<TD ALIGN=CENTER>(Space)</TD>'
(13) + '</TR>');
(14)cCount = 33;
(15)while (cCount < 255) {
(16)document.write ('<TR>'
(17) + '<TD ALIGN=CENTER>#' + cCount + '</TD>'
(18) + '<TD ALIGN=CENTER>&#' + cCount + ';</TD>'
(19) + '<TD ALIGN=CENTER><FONT FACE="'+font1+'">&#' + cCount + ';</FONT></TD>'
(20) + '</TR>');
(21)cCount++;
(22)}
(23)document.write ('<TR>'
(24) + '<TD ALIGN=CENTER>#' + cCount + '</TD>'
(25) + '<TD ALIGN=CENTER>&#' + cCount + ';</TD>'
(26) + '<TD ALIGN=CENTER></TD>'
(27) + '</TR>');
(28)document.write ('</TABLE></CENTER>');
(29)//-->
(30)</SCRIPT>
(01)<-- Start JavaScript
(02)<-- Hide JavaScript
(03)<-- Set the var 'Symbol'
(04)<-- Write the Table Open
(05)<-- Write 'Char'
(06)<-- Write 'Normal'
(07)<-- Write the var 'Symbol'
(08)<-- Close the Row
(09)<-- Open a Row
(10)<-- Write the # for Space
(11)<-- Write the String 'Space'
(12)<-- Write the String 'Space'
(13)<-- Close the Row
(14)<-- Initialize 'cCount' After Space
(15)<-- Start a 'while' Loop
(16)<-- Open a Row
(17)<-- Write the # for 'cCount'
(18)<-- Write the Normal Char for 'cCount'
(19)<-- Write the Symbol Char for 'cCount'
(20)<-- Close the Row
(21)<-- Increment 'cCount'
(22)<-- Close the 'while' Loop
(23)<-- Open a Row
(24)<-- Write the # 256
(25)<-- Write the Normal Char for 256
(26)<-- Skip the Symbol Char for 256
(27)<-- Close the Row
(28)<-- Close the Table
(29)<-- Close Hide
(30)<-- Exit JavaScript
You can view this here.
Notice that the JavaScript is in the Middle of the Web Page.

This is the JavaScript for Scrolling Messages:
(01)<SCRIPT language="JavaScript">
(02)<!--
(03)scrtxt="Super Prices on Computer Hardware are Back!!! Do you want Your Own Copy of the Source Code?"
(04)var lentxt=scrtxt.length;
(05)var width=100;
(06)var pos=1-width;
(07)function scroll() {
(08)  pos++;
(09)  var scroller=""
(10)  if (pos==lentxt) {
(11)    pos=1-width;
(12)  }
(13)  if (pos<0) {
(14)    for (var i=1; i<=Math.abs(pos); i++) {
(15)      scroller=scroller+" "
(16)    }
(17)    scroller=scroller+scrtxt.substring(0,width-i+1);
(18)  }
(19)  else {
(20)    scroller=scroller+scrtxt.substring(pos,width+pos);
(21)  }
(22)  window.status = scroller;
(23)  setTimeout("scroll()",150);
(24)  }
(25)//-->
(26)</SCRIPT>
(01)<-- Start JavaScript
(02)<-- Hide JavaScript
(03)<-- Put in the Message to Scroll
(04)<-- Create var
(05)<-- Create var
(06)<-- Create var
(07)<-- Create a function
(08)<-- Increment 'pos'
(09)<-- Initialize 'scroller'
(10)<-- Test for End of String
(11)<--
(12)<-- Close the 'if'
(13)<-- Test for Less Than '0'
(14)<-- Start a 'for' Loop
(15)<-- Add Spaces to the end of 'scroller'
(16)<-- Close the 'for' Loop
(17)<-- Move thru the 'scroller' String
(18)<-- Close the 'if'
(19)<-- 'else'
(20)<-- Move thru the 'scroller' String
(21)<-- Close the 'if'
(22)<-- Put 'scroller' on the Status Bar
(23)<-- Set 'timeout' for Return
(24)<-- Close the function
(25)<-- Close Hide
(26)<-- Exit JavaScript
You can view this here.
Notice that the JavaScript is in the <HEAD> of the Web Page
and is Loaded from the <BODY> TAG:
<BODY BACKGROUND="dkbkrd.gif" BGCOLOR="#FFFFFF" onLoad="scroll();return true;">

View the Netscape JavaScript Tutorial here.

Back to the Table of Contents


Author: Dennis Kennedy
Copyright © 1998 dkFlyer
If you have any questions, email me.

Hosted by www.Geocities.ws

1