Special Characters:
\f - form feed
\n - new line
\r - carriage return
\t - tab
Event Handlers:
onFocus - user moves focus to object.
onBlur - user removes focus from object.
onSelect - user highlights text.
onChange - user changes value of object.
onSubmit - user submits form.
onClick - user clicks on button or link
onMouseOver - user moves cursor over link.
onMouseOut - user moves cursor off link.
onLoad - document or image finishes loading.
onUnload - user exits document.
onAbort - user stops loading process.
onError - document throws error or exception.
Native Constructors:
Array() - object is initialized as an array.
Date() - object is current date.
Function() - object is a function.
Image() - object is an image.
Option() - object is an select list option.
String() - object is an text string.
Object() - object in an empty object.
Number Base:
Decimal ...........: 652
Hexadecimal .......: 0x28c
Exponent Notation .: 6.52e2
-----------------------------------------------------------------------------
Regular Expressions:
switches:
i (ignore case)
g (global search for all occurrences of pattern)
gi (global search, ignore case)
regexp = /pattern/
regexp = /pattern/switch
regexp.global - boolean value (/'pattern'/g) is true.
regexp.ignorecase - boolean value (/'pattern'/i) is true.
regexp.lastIndex - specifies the index point from which to begin the next match.
regexp.source - contains the text of the regular expression pattern.
regexp.compile - compiles a string expression containing a regexp pattern into an internal format.
regexp.exec - searches for a match in the specified string. returns object of type null or array.
boolean regexp.test - tests whether a pattern exists in a string. returns object of type boolean.
var re1 = /(\/|\*|\+|-)/
var re2 = /.+(\/|\*|\+|-).+/
var re3 = /\d|\./
var re4 = /^[^\/\*\+].+\d$/
var re5 = /\./
if(result.innerText.match(re2)&&event.srcElement.innerText.match(re1))
-----------------------------------------------------------------------------
Notes:
To parse an option value within a select within a form:
alert(form_name.select_name.options[font_name.select_name.selectedIndex].value)
eval('expression') - evaluates a string of javascript code.
toString() - returns a string representing the object.
valueOf() - returns the primitive value of the object.
watch(prop) - watches for a property to be assigned a value and runs a function on event.
unwatch(prop) - removes a watchpoint from a property of the object.
<input type="button" anme="example" value="&{document.title};">
var code = 'a'.charCodeAt(0)
document.write(arg) - arg = 'text to write to HTML doc @ runtime'.
document.writeln(arg) - arg = 'text to write to HTML w/<pre>'.
alert(arg) - arg = 'text to display in box'.
confirm(arg) - arg = 'text presenting argument choice returning true or false'.
if(confirm('do you want to do this?')) dothis()
prompt(arg,val) - arg = 'text presenting argument that should be entered'. val = 'default value'.
document.write(prompt('what do you want to write','whatever'))
if you are using input as integer or in a 'for' loop: parse[Int][Float](prompt())
[currentfunction].caller determines a functions trigger.
[currentfunction].arguments.length can be used with [currentfunction].arguments[0].
<input type=reset onClick="return confirm('are you sure?')">
<input type=file onClick="alert(this.type)">
<img src="&{(confirm('which')) ? 'a.gif' : 'b.gif'};">
this.value = (booleanORtest) ? 'true' : 'false'
for(variable in object) alert(variable) = for(prop in document)
break; will stop a loop.
if(i==10) continue; will force a loop to return to top.
for(var i=0,j=10;i<=10;i++,j--) { statements }
alert('a'.charCodeAt(0))
with(document.forms[0]) alert(elements[1].type
alert('4 is of type ' + (typeof 4))
this.data = eval(prompt('what?')) = converts string to numbers.
this.data = parseInt(prompt('what?')) = converts string to integer. NaN else.
this.data = parseFloat(prompt('what?')) = converts string to floating point or decimal. Nan else.
alert('alert is type of '+(type of alert))
document.write("The fee is " + (isMember ? "$2.00" : "$10.00"))
<a href="javascript:void(0)">Click here to do nothing</a>
escape() - removes all illegal characters
unescape() - restores all illegal characters
<input type=text onKeyDown='parent.keyDown(event,this)'>
for(var i=0,j=10;i<=10;i++,j--)
document.writeln("a["+i+","+j+"]= " + a[i,j])
Testing for Number:
function valnum(arg) {
for(var i=0;i'9') {
//alert(digit+' is not a number.')
return false
}
}
return true
}
Random Number:
function randomnumber(min,max) {
return (Math.random() * (max-min) + min)
}
if (navigator.userAgent.indexOf("MSIE") > 0) {
var sSize = (document.body.clientWidth + ' ' + document.body.clientHeight);
return sSize;
} else {
var sSize = (window.outerWidth * window.outerHeight);
return sSize;
function textWidth() {
if (document.layers)
alert('width = ' + document.layers['myId'].document.width + ' height = ' + document.layers['myId'].document.height);
else if (document.all)
alert('width = ' + document.all['myId'].clientWidth + ' height = ' + document.all['myId'].clientHeight);
}
//---------------------------------------------------------------------------
// These function represents window manipulation methods.
//---------------------------------------------------------------------------
function lib_win_resize(w,h) {
if(ns4) {
top.outerWidth = w
top.outerHeight = h
}
else if(ie4)
top.resizeTo(w,h)
}
function lib_win_maximize() {
if(ns4) {
if(top.screenX>0 || top.screenY>0)
top.moveTo(0,0)
if(top.outerWidth < screen.availWidth)
top.outerWidth=screen.availWidth
if(top.outerHeight < screen.availHeight)
top.outerHeight=screen.availHeight
}
else if(ie4) {
top.moveTo(-4,-4)
top.resizeTo(screen.availWidth+8,screen.availHeight+8)
}
}
//---------------------------------------------------------------------------
// This function represents string validation methods.
//---------------------------------------------------------------------------
<form name="signup" action="" method="" onsubmit="xsubmit()">
function xsubmit() {
var str= document.forms.signup.elements["q211"].value
if(str.length < 3) {
//------------------------------
// Value must be at least 3 chars.
//------------------------------
alert("Member ID must be at least 3 characters in length!")
return false
}
if(str.indexOf(' ')!=-1) {
//------------------------------
// Value must not contain blanks.
//------------------------------
alert('Blank(s) are not allowed in Member ID!')
return false
}
//------------------------------
// check for valid characters.
//------------------------------
var valid_id= 'abcdefghijklmnopqrstuvwxyz0123456789_.'
for(var i=0; i