For your first script we will look at the Javascript alert dialog box. Take a look at the script below, then I will explain it.
<script type="text/javascript">
|
|
For this small script we use the Javascript alert() function within the script block.
When the web page is loaded the Javascript code causes the browser to open an alert box containing your message withing the quotes. So that's all it is, to have your message appear just place it within the alert function inside quotes.
Note: It's good coding practice to end statements with the semi colon ;, although Javascript doesn't require it like some languages (PHP) it's good to get in the habit of adding it.
Variables.What is a variable? A variable is a place in which you can store data.
When you come to naming variables you must be aware of certain things. A variable can have any letter, digit and even the underscore _ may be used, but the variable may not begin with a digit.
Examples of valid variables:
abcd
my_variable
var32123
To create a new variable, you use the Javascript "var" keyword. I'll show you with a small script.
<script type="text/javascript">
|
|
The text string is stored inside the variable called my_message.
The variable name is called to the Javascript alert function that we talked about earlier, so when you run the script you will get an alert box displaying the string which is stored in the variable.
That's all for this tutorial, I hoped it helped you get a basic understanding of Javascript.
| Discuss Tutorial: Introduction to JavaScript | 0 Comments |