From NoskeWiki
Jump to navigation Jump to search


JavaScript (JS) is an computer programming language interpreted by all modern web browsers and used within HTML pages in web development. Implementations allow client-side scripts to interact with the user, alter the displayed page content, communicate asynchronously and control the browser. Sadly there are subtle differences in the language between different browsers, meaning libraries like jQuery and Google Closure have become popular to make sure code work across all major browsers.

Child Pages

Related/Child Pages:

Text Conversion:

Syntax Highlighting:


Common JavaScript Code

JavaScript Tags Within HTML

These tags are used for the bulk of your JavaScript scripts. Typically functions are written in the head tags, although most work within the body as well.

<SCRIPT LANGUAGE="JavaScript" TYPE="text/JavaScript">
function displayError(errorString) {
  window.alert("ERROR:" + errorString);

Now you can call this function from a hyperlink:

<a href="#" onClick="displayError('sorry, this link does not work');" >click here</a>

.... or other objects like buttons:

<input type="button" value="Test" onDblClick="displayError('do not double click me')" >

Windows Alert

window.alert("This is an alert box - annoying but sometimes useful");

Array Declaration

myArray1 = ['0','1','2'];            // Array with length 3 and 3 strings.
myArray2 = new Array(0,1,2);         // Array with length 3 and 3 numbers.

myArray3 = new Array(3);             // Empty array with 3 elements.
myArray3[0] = 'one';
myArray3[1] = 'two';
myArray3[2] = 'three';

Status Bar

window.status = 'This text will appear in the bottom status bar';

Output Text

document.write('Hello there');

Open Window of Fixed Size

<a href="" target="Search" 
onClick="var W ='', 'Search', 'width=400,height=200,menubar=0,scrollbars=0,resizable=1'); if (W) { W.focus(); }">
google search </a>

see also: dottor web reference for w3schools - Window open() Methodd

Yes/No Dialog

The 'confirm' dialog displays an 'ok' or 'cancel' option

if (confirm('Are you \n sure?')) {

See Also