Please check this website: http://www.w3schools.com/JS.
1. How to Handle Simple Browsers
Browsers that do not support JavaScript, will display JavaScript as page content.
To prevent them from doing this, and as a part of the JavaScript standard, the HTML comment tag should be used to "hide" the JavaScript.
Just add an HTML comment tag <!-- before the first JavaScript statement, and a --> (end of comment) after the last JavaScript statement, like this:
<html>
<body>
<script type="text/javascript">
<!--
document.write("Hello World!");
//-->
</script>
</body>
</html>
2. Where to Put the JavaScript
JavaScripts in the body section will be executed WHILE the page loads.
JavaScripts in the head section will be executed when CALLED.
3. JavaScript Popup Boxes
Alert Box: alert("sometext");
Confirm Box: confirm("sometext");
Prompt Box: prompt("sometext","defaultvalue");
<html>
<head>
<script type="text/javascript">
function show_prompt()
{
var name=prompt("Please enter your name","Harry Potter");
if (name!=null && name!="")
{
document.write("Hello " + name + "! How are you today?");
}
}
</script>
</head>
<body>
<input type="button" οnclick="show_prompt()" value="Show prompt box" />
</body>
</html>
4. JavaScript For...In Statement
The for...in statement loops through the elements of an array or through the properties of an object.
for (variable in object)
{
code to be executed
}
5. JavaScript Events
Events are actions that can be detected by JavaScript.
(1) onLoad and onUnload
To be continued.
1. How to Handle Simple Browsers
Browsers that do not support JavaScript, will display JavaScript as page content.
To prevent them from doing this, and as a part of the JavaScript standard, the HTML comment tag should be used to "hide" the JavaScript.
Just add an HTML comment tag <!-- before the first JavaScript statement, and a --> (end of comment) after the last JavaScript statement, like this:
<html>
<body>
<script type="text/javascript">
<!--
document.write("Hello World!");
//-->
</script>
</body>
</html>
2. Where to Put the JavaScript
JavaScripts in the body section will be executed WHILE the page loads.
JavaScripts in the head section will be executed when CALLED.
3. JavaScript Popup Boxes
Alert Box: alert("sometext");
Confirm Box: confirm("sometext");
Prompt Box: prompt("sometext","defaultvalue");
<html>
<head>
<script type="text/javascript">
function show_prompt()
{
var name=prompt("Please enter your name","Harry Potter");
if (name!=null && name!="")
{
document.write("Hello " + name + "! How are you today?");
}
}
</script>
</head>
<body>
<input type="button" οnclick="show_prompt()" value="Show prompt box" />
</body>
</html>
4. JavaScript For...In Statement
The for...in statement loops through the elements of an array or through the properties of an object.
for (variable in object)
{
code to be executed
}
5. JavaScript Events
Events are actions that can be detected by JavaScript.
(1) onLoad and onUnload
To be continued.