JavaScript concept (Appendix G)

Concept

Reference

Syntax

Example

Meaning

Object

Fig.9-3

object_name

window

frame

form

An element in a web page

Property

Fig.9-7

object_name.property

window.status="Please register with us…"

var version=navigator.appversion

The description of an object

Method

Fig.9-12

Object_name.method()

history.back()

window.alert("Please register with us first")

document.write("Thank you for registering with us")

 

Actions that can be carried out by an object

Hierarchy

Fig.9-6

Dot syntax

document.Registration.FirstName

The way objects are organized

Event

Fig.9-15

event_name

Abort

change

focus

A user's action

Event handler

Fig.9-13

<tag event_handler = "JavaScript commands">

<BODY onLoad="document.bgcolor='green';">

A way of telling the browser how to run a set of commands whenever a specific event occurs

Event method

Fig.9-21

Object_name.event_method

document.Registration.FirstName.focus()

To emulate an event

Selection list

Fig.9-24

document.FORM.FIELD.options[index].value

document.FORM.FIELD.options[index].text

document.FORM.FIELD.selectedIndex

document.Registration.State.options[0].text="AL"

 

 

User input

Pg.9.42

prompt("message","default_text")

prompt("Do you want to register with us?", "Type yes/no here:")

 

Selected object

Pg.9.30

this

OnBlur="chknum(this, 'Area Code', 3)"

 

 


JavaScript Programming concept (Appendix H)

Concept

Reference

Syntax

Example

Meaning

Variable

Pg.8.11

var variable

var Today

A named element in a program for storing data

Expression

Pg.8.19

var variable="value"

var variable = 1 + 2

var flag = 1

A way to assign values to variables

Function

Pg.8.23

function name(parameters)

{

    command

   

    return variable

}

* place between the <HEAD> tags

function prtdate()

{

  var Today=new Date();

  var Day=Today.getDate();

  var Month=Today.getMonth();

  var Year=Today.getFullYear();

  document.writeln("<CENTER>Today is "+Month+"/"+Day+"/"+Year+"</CENTER>");

}

A series of commands that either performs an action or calculates a value

Conditional

Pg.8.31

if (condition)

{

    commands if true

}

else

{

    commands if false

}

   

if (ans == "yes")

{

  close();

  window.open("form.html");

}

else

{

  close();

  window.open("frame.html");

}

 

To control when to perform certain actions

While loop

Pg.8.41

while (condition)

{

    commands

}

while (newemail.indexOf("@") == -1)

{

    newemail=prompt("Please enter a valid e-mail address", "enter your e-mail here");

 }

To execute certain actions a set number of times