Hi! Welcome to this tutorial. Before we start we must first check this tutorial is right for you. Please fill in the questionaire below and then click 'Check It' to find out.
You should be able to say yes to all of the above before commencing this tutorial.
Welcome to my Javascript tutorial! Before we begin we must first understand what Javascript is.
Its a language, like HTML, which you can use to spice your webpages up a bit. The form above,
asking you the three questions was a short Javascript I wrote. Javascript is my favourite website
language, because it is reasonably powerful, easy to use and almost everybody's computer will work
with it. It requires no plugins, downloads or extra work for the visitor. Its also very flexible.
It would take ages (It really would!) for me to write a complete Javascript tutorial, for javascript
is such a large language. However in this tutorial I will teach you the following:
- How to implement Javascript in a webpage.
- How to create, call and modify strings and variables.
- How to make forms and event handlers.
- A simple Login Script
IMPORTANT: You should try out all scripts on this page to help you learn this.
Implementation:
Example 1:
Wiggy Web: Javascript Tutorial!
If you look at Example 1 you will notice how the Javascript is surrounded by the 'script' tags. All Javascript must be placed in these tags. You will also notice how the Javascript was
placed after the title and before the closing head of the page. Generally Javascripts go there. But if the javascript is writing content directly to the page the script should go
in the appropriate place in the body. If in doubt place it in the head.
External scripts allow you to create a .js file with the javascript in it and then only put one line of javascript coding in your html page - this makes it neater and is more efficient if one
javascript is being used on more than one page.
.html file:
Title
.js file:
age = prompt("How old are you?","13");
alert("You are " + age + " years old!);
By the way you can shorten the opening Javascript tag, without any problems.
Instead of:
Use:
The reason this works fine is because Javascript is the default scripting language for browsers.
Strings and Variables
Strings are blocks of text, e.g. 'made of cheese'. Variables are numbers, like '15' or '200'.
Defining them: (I am merely putting down the script)
Example 2:
The above script shows how you can use one variable for multiple things.
Also, instead of a=3, you could use the method shown in Example 1, a = prompt(...
Forms:
Forms are used to allow the client (visitor) to input data.
Form items include: Text boxes, textareas, buttons, radio boxes, check boxes, password boxes and pulldown menus.
Example 3:
The form action attribute usually specifies a cgi, asp or php file to handle the data. In this case however Javascript is selected, and although I have not written the submitdata() function by the end
of this tutorial you should be able to do so. In fact, I am now going to show you how to write a simple username and password login script.
The way this script will work is the entrance page will have a form on it asking for the visitor's username and password. When they click a submit button the contents will be verified by a
javascript and if the information is correct the user will be able to enter.
Here is the complete page:
Password script
The above script first defines a function. It then creates two variables, username and password and makes them lowercase to prevent capitals making a problem.
It then checks the username to see if there is a matching password and if yes defines what happens (in this case moving to page 'pagepassed.html').
Congratulations! You have successfully completed this tutorial. Hopefully you have understood most of what we have covered.
There is definetely room for more and one day I may update this tutorial!
← ← Website Building Home ← ←