Tuesday, November 20, 2012

Javascript Functions

Function is a block of codes that performs certain task. A function contains code that will be executed by an event or by a call to the function.
You may call a function from anywhere within a page (or even from other pages if the function is embedded in an external .js file).
A function that does not execute when a page loads should be placed inside the head of your HTML document. Creating a function is really quite easy. All you have to do is tell the browser you’re making a function, give the function a name, and then write the JavaScript like normal.
HTML & JavaScript Code:
<html>
<head>
<script type=”text/javascript”>
<!–
function popup() {
alert(“Hello World”)
}
//–>
</script>
</head>
<body>
<input type=”button” onclick=”popup()” value=”popup”>
</body>
</html>
Display:

No comments:

Post a Comment