h  o  m  e

J a v a   S c r i p t   S t o p

JavaScript Home

  
 
Sponsor Area: 
This page is not a part of the JavaScript In 7 Lessons series.

Java Script

So what is Java Script?  Java Script, in its most simple form, is a client-side scripting language that is often employed to add interactivity and function to web pages.  Client-side means that Java Script runs on the client's computer, yours, versus server-side, the site's computer, i.e. Yahoo's. 

To use Java Script, you would simply add the Java Script code directly onto your HTML pages.  It is possible to work with Java Script without knowledge of  HTML if you use a WYSIWYG web page editor such as PageMill or FrontPage, however, the techniques that follow will most likely require you to manipulate the HTML text directly.  Familiarity with HTML is, at any rate, a good thing since some WYSIWYG web page editors tend to behave badly when the page design gets complicated.

For all the examples on Java Script Stop, you can use any text editor, such as wordpad, to type in the sample, as long as you save it as plain-text.   Better yet, you can use the cut-and-paste technique to achieve a more rapid result.   You will also need a Java Script activated browser to view the result of your Java Script, and the Java Script samples on our page.

Hint:  You can view the HTML that is behind most web pages on the internet, by choosing VIEW, then SOURCE from the toolbar of your favorite browser.

Fun with images

Here, we will show you how to make the graphics on your web pages respond to user's input.

Look first at this example: move your mouse pointer over it.

The button changes from green to red and back as your mouse pointer moves over and out of the image.  Actually, it is not only the color of the button that changes, but the image of the button itself.

For some reasons, the examples on this page does not work with Netscape browsers.  I believe that for the two examples on this page to work, the images must be links or references to URLs for Netscape browsers to pick-up the events.  This is not an endorsement for Internet Explorer.  I have both Netscape and Microsoft browsers on my laptop.  It just happened that I only tested this page with Internet Explorer.  If you know how to make the events work in Netscape browsers, without making them links.

The page actually contains the images of two buttons that look the same except for their colors, one green and one red.  When the mouse moves over the image, the green button image is replaced by the red button image.  When the mouse moves out of the image, the green button image is returned, creating the illusion that the button changes color when the mouse pointer moves over it.

That was pretty simple, but how does it work?  Here is the little bit of code that makes the button changes color:

<img src="images/greenbutton0.gif"

onMouseOver="document.images[1].src='images/red_button0.gif';return true;"

onMouseOut="document.images[1].src='images/greenbutton0.gif';return true;" width="25"

height="19">

Notice the   "onMouseOver=" and "onMouseOut=" parts of the HTML?   onMouseOver and onMouseOut are known as EVENTS.  The reason that they are called events is because they tell your browser what to do in the "event" that a mouse pointer passes over your picture, and what to do in the "event" that a mouse pointer moves out of it.

The action that is to be taken place when the an event occurs is put in double quotes and what goes inside the quotes, in this case is Java Script.

Notice that in our example, the Java Script inside the quotes both started with "document.images[1].src='path of picture'".  If you think of "document" as your your web page, "images" as the pictures in it, and "src" as the source of your picture or where it comes from then you won't need much more to underderstand our example.

Because what we really want to do when a mouse pointer passes over our image is to change the way it looks by displaying another picture in its place, we need to concern ourselves with the source of the picture, therefore "src".  Since the "src" we are talking about is the source of a picture or image, therefore "images".  Now we have "images.src".  But there is a small technicality here.  We want to change only the picture that the mouse pointer is passing over and not that of any other ones, so now we must specify which one.

Instead of "images.src", now we specify "images[n].src", where n is the "n"th image on the page.  In our example above, n=1, because the green button image is the second one on our page. 

The first is the "CentralStation" logo.  If you did want to refer to Central Station's logo, then n=0.  In computer land, "0" (zero) usually represents the first element in a set.  This is why the image source to the first image is referenced as "images[0].src" and the image source to the second image is referenced as "images[1].src".

To make it clear that the image we are talking about is an image on the current web page or document, we append "document" to the front of "images[n].src".

In order to swap our current image out with another image, we use the equal sign "=", and the path of the new picture in quotes, single quotes this time.  Single quotes are used when you need to specify quotes within quotes so as not to confused the browser.

For now, we want to terminate our actions with a Java Script's "return true" statement.

Lastly, a semi-colon is required to separate the Java Script statements from all sticking together, and make it possible for the browser to interpret them successfully.

Here is another way to use the Java Script statements that you just learned.

 

images/blank.gif (814 bytes)

images/blank.gif (814 bytes)

images/blank.gif (814 bytes)

images/blank.gif (814 bytes)

images/blank.gif (814 bytes)

Run your mouse pointer over the numbered buttons

 

To view the code for the second example, just click on VIEW, then SOURCE on the menu bar of your browser.

Until next time, have fun and experiment.   I have not thought of what to write for the next column yet so just drop Central Station a line via e-mail if there is something you want to see in particular.

Script Station is looking to serve its visitors better by offering services that are valuable to you.

 

Thank-you for visiting Central Station.

Homepage

Copyright of Script Station - All rights reserved

   
Psend kept free because of these great sponsors.a..

Other Sponsors

electrical connectors, Mangosteen Juice, real estate short sale, Jupiter FL real estate,

Furniture Markdown

Great Deals on furniture - Free Shipping!
Discount Furniture
Daybeds
Metal Beds
Platform Beds
Futons

Y-Net Wireless Internet

Denver area high speed wireless privider.
Colorado High Speed Internet, Wireless Internet Denver, VOIP Denver CO, T1 provider Denver, Denver Wireless ISP , Denver Internet Access,

Dog House Technologies

Doghouse Techonologies is located in Tampa Bay FL and offer professional web design, ecommerce development and custom application design for the internet.
Tampa Bay Web Design, E-Commerce Web Design, Tampa Bay Search Engine Marketing, Tampa Web Hosting, Florida Web Design, Custom Application Development, Search Engine Optimization,