JavaScript - An open source scripting language, it allows the creation of dynamic web page content.  Home Web Programming JavaScript The Basics of Java Script
Your Ad Here

The Basics of Java Script


In order to become a better JavaScript programmer, you need to understand the basics of Javascript. The last installment of Javascript Basics will go over arrays and events. These topics are fairly easy and should not require too much work.

Arrays

Arrays allow you to ceate variables that are somewhat similar. For example, say you have a set of variables like the list below:

spoono1 = .5;
spoono2 = 1;
spoono3 = 1.5;
spoono4 = 2;
95 more elements...
spoono100 = 50;

As you can see the basic pattern is spoonox = x/2. Say I have 100 of these variables and I don't want to type 100 lines. I can use an array which looks like this (notice the first line, new should be all small letters, and the A in Array must be capitalized):

spoono = new Array
for (x = 1; x <= 100; x = x +1);
{ spoono[x] = x/2};

This creates the array and individual variables can be called up using the following example syntax:

spoono[50] = 25;

Events

Events tell Javascript when to be activated. For example in the Alerts Tutorial we had the alert box popup when the user clicked on a button. We used the onClick event so that an alert came up when the user clicked a button. So, here is a list of some other events and their uses in HTML coding:

Event Function HTML Use
onMouseOver Activates Javascript when a user rolls his mouse over an object. Used in links tags and used for animated buttons.
onMouseOut Activates Javascript when a user rolls his mouse off of an object. Used in links tags and used for animated buttons.
onClick Activates Javascript when a user clicks something. Used in links tags and forms (buttons, form fields, etc.)
onSubmit Activates Javascript when a user presses the Submit button. Used in forms.
onLoad Activates Javascript when a page finishes loading. Used in the body tag.
onUnload Activates Javascript when a user leaves a page. Used in the body tag.


Author's URL: Brian Fusco
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

Web programming � everything from the basics of visual design and architecture to the specifics of applications, graphics, and scripting. More Web Programming: Most Popular Materials | Fresh Materials | More JavaScript Tutorials at LearnPHP.org

Add comments to "The Basics of Java Script"

Only registered users can write comment

No comments yet...