|
|
SITE MAP
Become a member
Members Login
Downloads
Backbone Tutorials
HTML Tutor
CSS Tutor
JavaScript Tutor
Website Promoting
Beyond The Basics
Meta Tags Tutor
HTML 4.01 tags/reference
Dynamic Websites
Non-technical Tips
Password Protection
Image Maps
Banners
Advanced forms tutor
Advanced frames tutor
Advanced tables tutor
Need Help
Contact Info
FAQ
Web Resources
|
JavaScript tutor- Lesson 2 If you ever took "advanced math" you know what a function is for. A function is used when there's a repetition. For example, the formulae: y=(x+67)*32.5 is a function. If you give the function a value for x, it will give you a value for y. For now all you need to know is that in the above function x is a variable. A variable can have any value. It can be 5, 6, 7, 1000 etc. It doesn't have to be a number. In some cases it can be something like "John". Consider the following:
<html>
<head>
<title></title>
<script type="text/javascript">
function MyMessage() {
name="John";
alert(name);
}
</script>
</head>
<body>
<a href="javascript: MyMessage()">Say Something</a>
</body>
</html>
In this case, name is a variable. It can have any value. Also notice that the value of a variable is enclosed in quotes but the variable itself isn't. And a semicolon (;) is used to separate one statement from another. Now give this a shot:
<html>
<head>
<title></title>
<script type="text/javascript">
function MyMessage() {
name="John";
alert("My name is " + name);
}
</script>
</head>
<body>
<a href="javascript: MyMessage()">Say Something</a>
</body>
</html>
Notice the use of + to connect a variable with some text. What If I wanted to add an exclamation point after the statement?
<html>
<head>
<title></title>
<script type="text/javascript">
function MyMessage() {
name="John";
alert("My name is " + name + "!");
}
</script>
</head>
<body>
<a href="javascript: MyMessage()">Say Something</a>
</body>
</html>
Don't move on to the next lesson until you understand what's going on here.
|
PGTUTOR is an award winning website. In the past 2 years, we've won over 20 legitimate awards. Go to our awards page to verify for yourself.
You're not taking a risk when buying our products. If for any reason you're unsatisfied with the quality of our product(s), we'll refund your money. Also, you get to keep the product you bought. |
||