Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
28 views

Basic Javascript Tutorial

This document provides an introduction to basic JavaScript concepts including: 1) How to include JavaScript code in HTML files using <script> tags or external .js files. 2) How to write simple test expressions like alerts. 3) The basics of variables, data types, and how to define and assign variables. 4) How to create functions that can take parameters and be called from HTML links.

Uploaded by

DarkItachi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Basic Javascript Tutorial

This document provides an introduction to basic JavaScript concepts including: 1) How to include JavaScript code in HTML files using <script> tags or external .js files. 2) How to write simple test expressions like alerts. 3) The basics of variables, data types, and how to define and assign variables. 4) How to create functions that can take parameters and be called from HTML links.

Uploaded by

DarkItachi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Basic JavascriptTutorial

Welcome to my firstjavascript tutorial. I want to explain the basic structure of an document. Later, I will show you how to use variables, build basic functions with parameters. There are two types of using javascript in our html / php file. The first one is defining a <script> section, like this:
<script type= text/javascript > /* Javascript (multi line comment) */ //One line comment </script>

Instead of the parameter type= text/javascript you can also use language= javascript . The second possibility is creating an external javascript file with the file extension *.js

Go ahead and create a new textdocument. Change the filename to something like script.js. In your html file you can simple write:
<script type= text/javascript src= script.js ></script>

Now, every code which is used in the file script.js will be executed.

A simple test expression, for make sure, that it works is:


alert( test ); //This will popup a messagebox with the text given in the first and only parameter.

In your *.js file you must not use the <script> tags.Only write down the simple expression.

In Javascript like in the most programming languages there are also Variables. In Javascript you define a variable like this:
Varvariable; variable = test //This is called a string. Thereareintegers, floatsandmore.

or:
Var variable = test ; //String Var variable2 = 1337; //Integer

For example:
varmsg = Hello World ; alert(msg);

A messagebox with the text Hello World should appear now, when executing the script.

In your html file place a link like this, to call a javascript function:
<a href= javascript: [function] >Click</a>

The function must have been defined above. If [function] is givemeanalert() then the function must have been defined like this:
<script type= text/javascript > Functiongivemeanalert() { alert( test ); } </script>

If you click on the link, a messagebox with the content test should appear.

If you want to use parameters in functions:


<script type= text/javascript > Functionbananas(count) { alert( Youhavegot + count + bananas! ); } </script> <a href= javascript: bananas(5) >How much bananas do I have ?</a>

That s all. Note: This tutorial is made for a friend. He s got much experience in using other languages. If you can t understand, please use another tutorial for learning javascript. Sorry.

You might also like