W3Schools

 

home HOME

JS Basic
JS HOME
JS Introduction
JS How To
JS Where To
JS Variables
JS Operators
JS Functions
JS Conditional
JS Looping
JS Guidelines

JS References
JS String Object
JS Array Object
JS Date Object
JS Math Object
JS Window Object
JS Frame Object
JS Form Object
JS Browser Object

Examples/Quiz
JS Examples
JS Quiz

JavaScript Examples

previous next

Note: Most of the examples require IE 4.0+, Netscape 7+, or Opera 7+!

Basic

Write text with JavaScript
Format text with HTML tags

Where to put the JavaScript

JavaScript in the head section
JavaScript in the body section
An external JavaScript

Variables

Declare a variable, assign a value to it, and display it

Functions

Function
Function with an argument
Function with an argument 2
Function that returns a value
Function with arguments, that returns a value

Conditionals

If statement
If...else statement
Random link
Switch statement

Looping

A for loop
Looping through HTML headers
A while loop
A do..while loop

String Object

Count characters in a string (length() method)
Test if a string contains a specified text (indexOf() method)
Test if a string contains a specified text (match() method)
Return a specified part of a string (substr() method)
Uppercase or lowercase characters? (toLowerCase() and toUpperCase() methods)

Array Object

Make an array that stores names
Find out how many elements an array contains

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
Display an alert box
Display an alert box with line breaks
Disable right-click IE only
Disable right-click only on content 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 fullsize window
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 and Opera 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
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


previous next

Product Spotlight


Hosting Spotlight


Phone Cards

Phone Cards Online

International and domestic phone cards for US customers.

Great affiliate program.


We Help You For Free. You Can Help Us!


Jump to: Top of Page or HOME or Printer Friendly Printer friendly page


Search W3Schools:


What Others Say About Us

Does the world know about us? Check out these places:

Google  Yahoo  Alta Vista  MSN  Lycos  Excite  Ask Jeeves  HotBot


W3Schools is for training only. We do not warrant the correctness of the content. The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 1999-2004 by Refsnes Data. All Rights Reserved.


Validate How W3Schools was converted to XHTML Validate

Web charting
Web based charting
for ASP.NET


WEB HOSTING

$15 Domain Name
Registration
Save $20 / year!



UK Domain Names
Web Hosting
Merkaweb Dominios


Buy UK Domain Names
Register Domain Names


Website Hosting
Domain Hosting
Web Hosting


Cheap Domain Names UK


Domain Names UK
Quality Web Hosting
Webmail & POP3 Email


Web Hosting UK
Dedicated Servers UK
Domain Names UK


Business Web Hosting
Free Web Hosting
Cheap Web Hosting
Web Hosting Reseller


Website Design UK

HOTELS

Amsterdam Hotels
Boston Hotels
Chicago Hotels
London Hotels
Los Angeles Hotels
Miami Hotels
New York Hotels
New Orleans Hotels
Paris Hotels
Rome Hotels
Hotel Reservations


Hotel Directory
Hotel Rooms

Web Building

Website Templates
Website Builder
Flash Templates
Web Templates

Shopping

Garden decor
Online Coupons
Cooking tools
Men & women clothing
Office supply

Software

Student Price Software


Your Own Web Site?

Read W3Schools
Hosting Tutorial








WebDev Books

The Web Design Business Kit Grow Your Web Design Business!

HTML Utopia: Designing Without Tables Using CSS Learn CSS Positioning the easy way!

Build Your Own Database Driven Website Using PHP & MySQL Learn PHP & MySQL the easy way!

SELECTED LINKS

University Online
Master Degree
Bachelor Degree


Web Security
Web Statistics
Web Standards

Web Quality