1. Prompt Box

This example takes the words you typed into the box when the page loaded and writes them into the page dynamically. The Javascript that triggers the prompt box is between the <head> tags.

var yourName=prompt("What is your name?","");

Some javascript is written into the body of the page that picks up that name and writes it dynamically into the page title.

<script language="javascript">
    document.write('<h1><font color=red>Javascript Examples for ' + yourName + '</font></h1>')

2. Alert Box

Those annoying greetings that you often see on many websites are examples of alert windows. View one such annoying greeting by clicking the button below.

function greeting() {
    alert("Hi there. Welcome to Javascript!")

3. Popup Window

A popup window differs from an alert box in that it's actually an HTML file. It can be an existing HTML file or one that is created dynamically. Clicking on the button below will launch a new window that is 414 pixels high by 640 pixels wide and will appear in the upper left-hand corner of the screen.

function openWin(page) {
    window.open(page,"example",     "screenX=0,screenY=0,top=0,left=0,resizable=yes,scrollbars=yes,width=640,height=414")

4. Time Clock

Javascript can access your computer's internal clock and display it dynamically.

function dailyTask() {
    var tod = new Date();
    document.TimeForm.TimeOfDay.value = tod.toString();
    timerID = setTimeout("dailyTask()",1000);

Current time:

Okay, let's get started...