![]() |
![]() |
The purpose of this page is to demonstrate some of the features of HTML that you should be using in your work.
Values: For javascript scripts to work, there must be some content so that the browser knows what to when an event handler has been triggered
Values provide this content and come in several different forms
They can contain numbers or words and are used in several different ways
Examples of values include:
Other properties of documents include:
value type Meaning Example Numerical Any number 247365 String Any characters inside " " "Like this!" Boolean operator True/False True These are also values but less frequently used Null Empty, no meaning Object value linked to an object Function value returned by a function
Variable:When you use a variable in a script, you assign it to a variable
For example, a string value could be the title of a web page, such as "Javascript Tutorial"
To use this value, you have to assign it to a variable, such as "myPage"
It would look like this:
myPage = "Javascript Tutorial"
In this syntax, the < = > is shorthand for "is set to", so the statement actually reads:
The variable "mypage" is set to the value "Javascript Tutorial"
You can create as many variables as you need
Variable names follow UNIX conventions: no spaces or punctuation
They are also case sensitive:
"myPage" is not the same variable as "MyPage"
Operators: to use variables in a script, they must be linked together with operators
These are taken from math and have similar meanings
Here are some common operators:
Operator name Meaning Example x + y (numeric) Adds x and y 3 + 5 = 8 x + y (string) Adds text of x and y Dog + head = Doghead x - y Subtracts y from x 5 - 3 = 2 x * y Multiplies x and y 3 * 5 = 15 x / y (string) Divides x by y 15 / 3 = 5 x % y Remainder when x is divided by y (Modulus) 15 % 4 = 3 x + + Adds 1 to x (after operation is over) y = x + + (if x = 9: y = 9, x = 10) + + x Adds 1 to x (before operation is over) y = x + + (if x = 9: y = 10, x = 10) x - - Subtracts 1 from x (after operation is over) y = x - - (if x = 9: y = 9, x = 8) - - x Subtracts 1 from x (before operation is over) y = x - - (if x = 9: y = 8, x = 8) - x Reverses sign on x - x (if x = 4, - x = - 4
Comparisons: To compare variables in a script, or to compare a script variable against the input provided by a user, comparisons are used
Here are the major comparisons you can use:
Comparison name action x==y If x equals y, it returns true 3 + 5 = 8 x!=y If x does not equals y, it returns true Dog + head = Doghead x>y If x is greater than y, it returns true 5 - 3 = 2 x>=y If x is greater than or equal to y, it returns true 3 * 5 = 15 x<y If x is less than y, it returns true 15 / 3 = 5 x<=y If x is less than or equal to y, it returns true 15 % 4 = 3 x&&y If x and y are both true, it returns true y = x + + (if x = 9: y = 9, x = 10) x||y If either x or y is both true, it returns true y = x + + (if x = 9: y = 10, x = 10) !x If x is false, it returns true y = x - - (if x = 9: y = 9, x = 8)
Here's how to begin putting scripts together
| Demo Page Navigation: |
DemoPage contents | About HTML | UNIX help | HTML tags | Lists | Links | Images |
| Imagemapping | Tables | Forms | Frames | Javascript | CSS (style sheets) | XML |
| Page by Howard Rosenbaum | |
| Find me at hrosenba@indiana.edu | http://www.slis.indiana.edu/hrosenba/www/Demo/Demo19.html |