Javascript. Not to be confused with Java. This is and will always be the most incomplete section of the HTML Workshop sections. There is an infinite amount of Javascript scripts that I could post here because of the many different ways the Javascript code can be written and utilized. I've posted some of my favorite scripts, but I still have many times more on my computer or in my head waiting to be posted here...if I feel like it. I'm not motivated at the moment, if you'll excuse me. Still, feel free to use whatever's already posted here. It's not much, but it's something.
1. The <script> Tags
The beginning script tag can also link to a .js file (a Javascript file). In such a case, a webmaster would place the script code inside a separate .js file instead of in the HTML file. Whenever the script is external, a webmaster links to it using the beginning script like this:
<script language="javascript" src="example.js" type="text/javascript">
<script>
<!--
(And the script contents will go here.)
//-->
<script>
//This is a comment. I can write whatever I want here, and it won't show. !@#$%^&*()
//Wheeeeeeeeeeeee!!!!!!!!!!! Comments...fun!
(And the script contents will go here, and comments can be placed within the script contents itself, as long as the contents are modified themselves.)
//Monkey comment in the middle!
(In other words, the contents can be split by comments and still work.)
onMouseOver - This is used for functions related to the moving of the cursor (mouse arrow) over something, be it a link, text, image, button, or whatnot.
onMouseOut - This is usually used after onMouseOver and is used when a cursor is moved away from a hovering position over a link, text, image, button, or whatnot.
window - This is not necessarily used alone. It's normally used with something added to it, as shown in the two examples below. This is used with functions involving the window of the browser, like in the launching of a new window or the maximizing of the current one.
window.alert
document - This is used for the creation or modification of contents or aspects of a webpage or HTML document, hence the name of the 'document' in the command. For example, it could be used to create text on the webpage or tamper with the colors on the page. Below are some examples of the document part of the script.
document.write
document.bgcolor
*Disclaimer: This was my second incomplete attempt at a concise overview of Javascript. It assumes that you already know HTML cold, and that you either a) already know C, C++, Java, etc., or b) can figure out what everything means from the code alone. And I won't explain the terms yet. I probably will when I have more time.
Script and Using Comments to Hide Script From Older Browsers
<script language="Javascript"> <!-- //--> </script> <script> <!-- //--> </script> <script> </script>Terms to Know: attributes Variables and Write
var blah blah = 3.14 var blahblah = 42 blahblah = "I am a jelly donut." document.write(blahblah) document.write("I am the master.<br>Do you like cheese?") document.write("<img src='image.gif'>") document.write('<img src="image.gif">')Terms to Know: local variables, global variables, declaring variables, initializing variables, string Operators
x+y (numeric addition or string concatenation) x-y x*y x/y x%y (remainder of x/y, modulus or mod.) x++ (x=x+1) ++x (x=x+1) x-- (x=x-1) --x (x=x-1) -x (reverse sign of x) var x = 3 var y = 4 x+y var a = "I like " var b = "cheese." a+bTerms to Know: operator, operand, concatenation, modulus if, else, functions...
if (x==y) { document.write("x equals y") } else { document.write("x does not y") } x == y x and y are equal x != y x and y are not equal x > y x is greater than y x >= y x is greater or equal to y x < y x is less than y x <= y x is less than or equal to y if (age < 20 && age >= 12){ document.write('You are a teen.') }Terms to Know: condition, statement Functions
function myAdder (number1, number2) { var total = number1 + number2 return total } document.write(myAdder(23, 56)) var today = new Date() document.write(today)Terms to Know: function Events
Click <a href='JavaScript:alert("Attention, your speaking rights have been suspended")'>here</a>. Click <a href='JavaScript:alert(myFunction)'>here</a>. <form name="clickbuttongetsanalert"> <input type="button" name="alert" value="Click for Alert" onClick='alert("Yahoo!")'> </form> <form name="clickbuttongetsconfirmation"> <input type="button" name="confirmDemo" value="Confirm dialog box" onClick='confirm("Can you think of a use for this?")'> </form> <form name="clickbuttongetspromptdialog"> <input type="button" name="promptDemo" value="Prompt dialog box" onClick='prompt("Enter some information")'> </form>
Mouse Over Link Changes Background Color
Back to Top
Mouse Over Picture, Picture Changes
Back to Top
Small Pop-Up Window
Back to Top
Showing Visitor's Name On Webpage (After Visitor Enters Name)
Back to Top
Option of Choosing Background Color By Typing Name of Desired Color
Back to Top
Option of Choosing Background Color By Selecting Preset Colors
Back to Top
Bookmark-this-site (simple)
Back to Top
Bookmark-this-site (advanced)
Back to Top
Button That Changes Color When Mouse Goes Over
Back to Top
Display Visitor Name on Page (by visitor entering text in pop-up box)
Back to Top
Display and Remember Visitor Name on Page (by entering text in pop-up box, using cookies)
Back to Top
GordeonBleu and its affiliates (there aren't any) apologize for the discontinued addition of samples to the Javascript section (year 1999).
©1999 - . HTML Workshop. GordeonBleu. Gordon Mei. |