Sourceforge SuperTable

SuperTable Example #3

Color Key
Control
DOM
Event
Object
References
Other
Category contains... Description contains... Snippet contains...  
Filter supports Regular Expressions
[ Refresh Table ]         [ Remove Table Row Color (for printing) ]
Category Description
 
Code Snippet
CSSForcing minimum table column width (without spacer image)
<th>
    Column title
<div style="width:10em; height:0px;"></div> </th>
ControlSimple true-false switch statement(myVal < 0) ? myVal = -myVal : myVal = myVal;
ControlCompound "for" statementfor (i = 0; i <= n && (found = txt.findText(str)) != false; i++)
ControlSimple true-false switch statement (nCodeString < 0) ? nCodeString = -nCodeString : nCodeString = nCodeString;
ControlUsing setInterval in the <body> tag // This example shows how to pass a parameter to the setInterval function
< body onload="window.setInterval('dynamic_yscroll(\'floater\')', 1)">
DOMAdding properties to DOM HTML objects (defineGetter & defineSetter)HTMLElement.prototype.__defineGetter__( 'foo', function(){return 'bar'} );
output = document.body.foo; //Output is 'bar'
DOMAppending new nodes oNew_cell=document.createElement("TD");
oNew_cell.innerHTML = sCell_text;
oNew_row.appendChild(oNew_cell);
DOMDOM HTML ElementsReferencing DOM HTML Elements

Node -> Element -> HTMLElement -> HTMLTableElement

Types of HTMLElement Objects ( DOM2 Standard )
* HTMLHtmlElement
* HTMLHeadElement
* HTMLLinkElement
* HTMLTitleElement
* HTMLMetaElement
* HTMLBodyElement
* HTMLFormElement
* HTMLTableElement
* HTMLInputElement
* HTMLParagraphElement

* Many Many more.. See:
http://www.w3.org/TR/2001/WD-DOM-Level-2-HTML-20011025/ecma-script-binding.html
DOM, DebugManually iterating through the DOM "body" node
for( i=0; i<document.body.childNodes.length; i++ ){
    ( confirm( document.body.childNodes.item(i).innerHTML ) ) ? 1 : last;
}
// Assumes that variable 'last' is NOT defined!
                    
DebugPrevent error messages from being processed by browserwindow.onError=null;
DebugUse confirm box to enable break in a loop
(useful when debugging -- allows you to break long loops at will)
while (1){
    ( confirm(i) ) ? 1 : last ;
}
// Assumes that variable 'last' is NOT defined!
EventDetect <enter> key
function detectEnter(evt) {
    if( evt.keyCode == 13 && evt.shiftKey ) {
        alert('enter key pressed');
    }
}
<textarea ... onKeyDown=&quot;detectEnter(event)&quot;>
ObjectRead value of form select objectvar list = document.myForm.selectList; //selectList is an Array
selectedValue = list.options[list.selectedIndex].value;
ObjectDynamically loading images on-the-fly (no precaching -- Slideshow) Use this technique when you have many large images that are referenced on the page but you don't want to precache them - Images will download on demand.
IMPORTANT!!
The link which loads the image must be called without the onclick event handler!! If it is called using the onclick event handler, then the image will load but not render. Call the image directly from the href as shown below:
    <a href="javascript:slideShow(-1)">back</a>
    <a href="javascript:slideShow(1)">next</a>
Here is the script for the slideshow:
function slideShow(dir) {
    if ( currentImg + dir > 0 && currentImg + 
           dir < imgArrayLength ) 
    {
        document.images['slideImage'].src = 
            eval( '"' + imgArray[ currentImg + dir ] + '"' );
        currentImg += dir;
    } else { alert("you are at beginning or end"); }
}
                    
ObjectOpen new window (most commonly used parameters)newWindow = window.open('popup.html', 'window-name', 'status=yes, menubar=yes, resizable=yes, scrollbars=yes, width=700, height=700');
// Note: there are a bunch of other options...
ReferencesDefining constants (opposite of variables -- Works only in Mozilla)const PI = 3.14159; //Constants can only be assigned ONCE
ReferencesVariable variablex = "var" + "A";
varA = 12;
alert( this[x] ); // displays 12
ReferencesVariable functionx= "my"+ "Funct";
myFunct = function(){return 99}
alert( this[x]() ); // displays 99
ReferencesReferencing functions and variables in a document Keyword "this" in <head> references the Window Object where all declared functions
and variables exist. Example:

this.functionName();
this.variableName;
References, DOMReferencing the Window Objectdocument.defaultView // Reference to Window Object.
document.defaultView.myVar // Reference to myVar in <head>
ReferencesVariable Naming ConventionsString_var
nNumeric_var
bBoolean_var
cLoopCounter_var
dDate_object
oObject
aArray
pParameter
eElement for(eProperty in oObject){}
CONSTANT_VAR
myFunction(pArgument)
ReferencesTreating a literal as an object (123).toString(16);
This treats the literal number 123 as a number object so that we can access it's method toString().
The example above converts the number 123 to it's hexadecimal value.
ReferencesGlobal Object Variable: Passing by reference example
box.stuffinside = 'stuff';


function box(arg){
    box.stuffinside += 'more';
}    
 
box2 = box;
box2.stuffinside = 'new stuff';


alert( box.stuffinside ); // Displays 'new stuff'
                     
RegexCommon form validation regex patterns
'name',  /\w+/,
'email', /^\w+(.\w+)*@\w+(.\w+)*.(net|org|com)+$/,
'phone', /^((\d-)?\d{3}-)?\d{3}-\d{4}$/,
'zip',   /^\d{5}(-\d{4})?$/
                    
SourceForge.net Logo