Passing information to a function
�@
�@
| <SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">.....</SCRIPT> | |
|
Attribute identifies to the browser which scripting language is being uesd. |
|
Attribute tells the browser that the script is plain text, organized as Javascript. |
|
The end. |
| /* This is comment. */ | |
|
The /* at the beginning of the lines tells JavaScript to ignore everying that follows until the end of the comment. |
|
The end of the comment. |
| <!-- Hide Script --> | |
|
Open the Html comment with the <!--, and end with --> |
| A function is a set of JavaScript statements that performs a task. Every function must be given a name and can be invoked, or called, by other parts of the script. Functions can be called as many as needed during the running of the script. | |
|
function saysomething( ) { alert(" seven years ago") } |
A function consists of the word function followed by the function name. There are always parentheses after the function name, followed by an opening brace. The statements that make up the function go to the following lines, then the function is closed by another brace. |
| <INPUT TYPE="BUTTON" VALUE="click" onClick="saysomething( )"> | Calling a function. Example 1 |
Passing information to a function
|
function saysomething( message
){ <INPUT TYPE="BUTTON" VALUE="click" onClick="saysomething('hello')"> |
Take some information and give it to a function to be processed. This is called "passing" the information. The variable message is a parameter of the function. When the function was called, the data' hello' got passed into the message parameter. Example 2 |
|
myMsg="Hey, check out" i=0 function scrollMsg( ){ window.status= myMsg.substring (i, myMsg.length)+ myMsg.substring(0, i-1) if (i<myMsg.length){ i++} else {i=0} setTimeout("scrollMsg( )", 50) } |
|
|
myMsg is a variable to set the text within the quotes. |
|
Sets window.status, the status line property of the window object. The method substring(x,y) acts on an object, and returns part of the string, starting with x and stopping at one character before y. |
|
The setTimeout command is JavaScript's way of adding a pause to a process. Inside the parantheses, you put the name of the function you want to call after pase. Then add the time period in millisec. |
|
<body> <a href="function.htm" onMouseover="window.status='when moves the pointer over here'; return true" onMouseout="window.status=' ';return true"> my girl</a> </body> |
|
|
Set window status object equal to the string'when moves the pointer over here'. Example 3 |
|
The return true is necessary to display the message, if it's not there, the message won't work. |
�@
�@