If you want something you've never had, you must be willing to do something you've never done!

Powered by Blogger.

JavaScript Functions (which behave like Java methods) 1

Cerita Semalam Aaz | 12:13 AM | ,



JavaScript Funcitons

  • A JavaScript function contains some code that will be executed only by an event or by a call to that function
> To keep the browser from executing a script as soon as the page is loaded, you can write your script as a function


  • You may call a function from anywhere within the page (or even from other pages if the function is embedded in an external .js file)

  • Functions can be defined either <head> or <body> section
>  As a convention, they are typically defined in the <head> selection

Example: JavaScript Function

<html>
<html>
<head>
<script type="text/javascript">
// If alert("Hello world!!") below had not been written within a
// function, it would have been executed as soon as the page gets loaded.
function displaymessage() {
alert("Hello World")
}
</script>
</head>
<body>
<form>
<input type="button" value="Click me!" onclick="displaymessage()" >
</form>
</body>
</html>

                                   

1 Responses So Far:

Anonymous said...

what is this conclude ?

Related Post

 
Back To Top