Where to put your script

Putting comments in scripts

Functions

Passing information to a function

Scrolling status Bars

Status Bar Message

�@

�@


Where to put your script

<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">.....</SCRIPT>
  • LANGUAGE="JAVASCRIPT"

Attribute identifies to the browser which scripting language is being uesd.

  • TYPE="TEXT/JAVASCRIPT
Attribute tells the browser that the script is plain text, organized as Javascript.
  • </SCRIPT>
The end.

Putting comments in scripts

/* 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 -->

Functions

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 ){
alert( 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

Scrolling status Bars

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="Hey, check out"
myMsg is a variable to set the text within the quotes.
  • window.status= myMsg.substring (i, myMsg.length)+ myMsg.substring(0, i-1)
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.
  • setTimeout("scrollMsg( )", 50)
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.

Status Bar Message

<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>

  • window.status='when moves the pointer over here'
Set  window status object equal to the string'when moves the pointer over here'. Example 3
  • return true
The return true is necessary to display the message, if it's not there, the message won't work.

�@

�@

Hosted by www.Geocities.ws

1