Professional Documents
Culture Documents
}
</script>
</body>
</html>
Onchange:
<html>
<head>
<script>
function preferedBrowser() {
prefer = document.forms[0].browsers.value;
alert("You prefer browsing internet with " + prefer);
}
</script>
</head>
<body>
<form>
Choose which browser you prefer:
<select id="browsers" onchange="preferedBrowser()">
<option value="Chrome">Chrome</option>
<option value="Internet Explorer">Internet Explorer</option>
<option value="Firefox">Firefox</option>
</select>
</form>
</body>
</html>
Onload:
<html>
<body>
<img src="w3javascript.gif" onload="loadImage()"
width="100" height="132">
<script>
function loadImage() {
alert("Image is loaded");
}
</script>
</body>
</html>
Onmouseup and Onmousedown:
<html>
<head>
<script>
function myFunction(elmnt, clr) {
elmnt.style.color = clr;
}
</script>
</head>
<body bgcolor="lightblue">
<p onmousedown="myFunction(this,'red')"
onmouseup="myFunction(this,'green')">
Click the text to change the color. A function, with parameters,
is triggered when the mouse button is pressed down, and
again, with other parameters, when the mouse button is
released.
</p>
</body>
</html>
}
</script>
</body>
</html>
Anchors[]:
<html>
<body>
<a name="html">HTML Tutorial</a><br>
<a name="css">CSS Tutorial</a><br>
<a name="xml">XML Tutorial</a><br>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"Number of anchors are: " + document.anchors.length;
</script>
</body>
</html>
Forms[]:
<html>
<body>
<form action="">
First name: <input type="text" name="fname"
value="Donald">
<input type="submit" value="Submit">
</form>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"Number of forms: " + document.forms.length;
</script>
</body>
</html>
Images[]:
<html>
<body>
<img src="pic_htmltree.gif">
<img src="pic_navigate.gif">
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"Number of images: " + document.images.length;
</script>
</body>
</html>
Navigator Object Properties:
<html>
<body>
<div id="demo"></div>
<script>
var txt = "";
document.close();
}
</script>
</body>
</html>