in black and white
Main menu
Home About us Share a book
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics

Javascript for dummies. Quick Reference - Vander

Vander Javascript for dummies. Quick Reference - Wiley Publishing, 2002. - 115 p.
Download (direct link): javascriptquickreference2002.pdf
Previous << 1 .. 23 24 25 26 27 28 < 29 > 30 31 32 33 34 35 .. 72 >> Next

Invoking submit methods:
document.myForm.submi tButton.cli ck()
Clicking on the Submit button sends a form to the URL value specified in the form’s HTML ACTION attribute. The data is sent as a series of attribute-value pairs, each pair separated by an ampersand (&).
*1 The text object is a single-line input field. (If you want a
multiple-line input field, see the textarea object, defined in the following section).
| Creating a text element:
«CINPUT TYPE="text" NAME*"1astName" VALUE="your name here"
I SIZE=30 onBlur="validate()" onChange*"validate()">
Accessing text properties: Form.lastName.defaultValue Form.1astName.type Form.lastName.value
70 textarea
Invoking text methods:
document .my Form. lastName.focusO document .my Form. lastName.blurO document .myForm. lastName.selectO
Atextarea object is just like a text object, except that instead of defining one scrolling input line, the textarea object defines a multi-line scrolling text box.
Creating a textarea object:
CTEXTAREA NAME="directions" R0WS=4 C0LS=60 onBlur="vali date()" onChange="di splay()" onFocus="welcome()" onSelect="changeMode()">
This is default text. You can type right over it, add to it, cut it, paste it, or copy it. </TEXTAREA>
Accessing textarea properties: Form.di rections.defaultValue document.myForm.di recti document.myForm.di recti ons.type document.myForm.di recti ons.value
Invoking textarea methods:
document.myForm.di rections.focus() document.myForm.di recti ons.b 1 u r () document.myForm.di recti ons.sel ect()
The wi ndow object is the top-level granddaddy object for all document objects, and you’re given the first one gratis, compliments of the <B0DY>. . . < / В 0 D Y > tag pair. If you want to create extra windows, the following example is the way to do it.
If you do create multiple windows, remember to tack the new window’s name (myOtherWi ndow, for example) in front of any associated property or method you access so that the interpreter knows which window you’re referring to at all times.
Creating a window:
Here’s the generic syntax for creating a window, followed by an example:
u/indou/ 71
windowVar = open("URL", "windowName",
["wi ndowFeatures"])
myOtherWindow = open("win2.html", "secondWindow' "toolbar=yes, 1ocati on=yes, di rectori es=yes, status=yes, menubar=yes, scrol1bars=yes , resi zable=yes, wi dth=250, hei ght=400")
Accessing window properties:
def a ill tStatus
sel f
Invoking window methods:
alertC'Form will be sent now...") blur() close()
confirm("Do you really want to quit?") focus()
myOtherWindow = openC'", "secondWindow",
"toolbar=yes, 1ocati on=yes, di rectori es=yes, status=yes, menubar=yes, scrol1bars=yes , resi zable=yes , width=250, hei ght=400") prompt("Enter the file name:", "testfile.txt") scroll(50, 100)
timeoutID=setTimeout("di splayAlert()", 2500) clearTimeout(timeout ID)
myOtherWi ndow.wri te("Here is myOtherWi ndow.")
72 JavaScript For Dummies Quick Reference
Data Types: Building Basic JavaScript Objects
Some kinds of objects, such as dates and strings, are really basic; they’re so basic, in fact, that almost every script you’ll ever write will probably contain a reference to them. Because they’re so common, JavaScript thoughtfully provides built-in classes for them — but because JavaScript is loosely based on C, these classes are still referred to by the conventional name of data types.
Unlike the objects that you find in Part III, JavaScript data types don’t have corresponding HTML tags — they’re pure JavaScript constructs. You declare them inside the <SC RI PT> . . . </ SС RI PT> tag pair by using JavaScript statements, as you can see in the following sections.
In this part...
v* Creating objects based on built-in data types и* Accessing object properties u* Invoking object methods
76 Array
An Array is an indexed list of things called elements. Element values can be whatever you want them to be — numbers, strings, or even other objects. You can fill an array with elements when you create it by passing values to the array constructor, or you can create an empty array and fill it with elements later.
Arrays are useful whenever you want to keep track of a group of related items.
arrayName = new Array(lelementl, elementZ, ... elementN \ arraySi ze])
var listOfPets = new Array("dog", "cat", "gerbil")
// signals that 2 initial elements are expected, but
// the interpreter won't complain if you assign more
var favoriteFoods = new Array(2)
favoriteFoods[0]="frozen yogurt"
favoriteFoods[l]="barbecued beef"
favoriteFoods[2]="stir-fry" // 3 elements is okay
var toDoList = new ArrayO
Accessing array properties: (
favori teFoods.length totypeName
Previous << 1 .. 23 24 25 26 27 28 < 29 > 30 31 32 33 34 35 .. 72 >> Next