Java Script Examples*

Return to Introduction

Date Object

Today's date
Current local time
Set date
UTC time
Display current weekday
Display a complete date with the name of the day and the name of the month
Running clock

Math Object

Round a number to the nearest whole number (round() method)
Random number between 0 and 1 (random() method)
Random number from 0-10 (random() method and round() method)
Test which of two numbers, has the highest value (max() method)
Test which of two numbers, has the lowest value (min() method)
Convert Celsius to Fahrenheit
Convert a character to Unicode

Window

Change the text in the <title> tag of a document IE only
Display an alert box
Display an alert box with line breaks
Disable right-click IE only
Display a confirm box
Display a prompt box
Open a new window when clicking on a button
Open a new window and control its appearance
Display a new full size window IE only
Place the new window
Close a window
Open multiple windows
Location
Press a button to view source
Bookmark page/Add to favorites IE only
Make page default homepage IE only
Refresh page
Change text in the status bar
Print page
When was this page last modified?
Scroll down
Scroll right
Scrolling effect

Image

Preload an image

Frames

Break out of a frame
Update two frames
Update two other frames
Update two iframes IE only

Forms

Validate an e-mail address
Validate a value
Validate a length of an input
Form validation
Set focus on an input field
Select text in an input field
Radio button
Checkbox
Select from a dropdown list
Select more than one option
Select menu IE only
Set focus on the next field when the current field's maxlength has been reached

Client info

Detect the client's browser
More details about the client
Detect details about the client's monitor
Redirect the user to different pages, depending on browser
Write a different message to the user, depending on the browser

Return to Introduction

Return to Index

*All of these examples are linked to w3schools.com, additional scripts are found here.

top of page