java script function and use

java script function-: A function is a reusable code block that will be execute by an event, or when the function is called. To keep the browser from executing a script when the page loads, we can put our script into a function. A function contains code that will be executed by an event or by a call to that function.

we can call a function from anywhere within the page( or even from other pages if the function is embedded in an external .js file. function can be defined both in the <head> and in the <body> section of a document. however to assure that the function is read/loaded by the browser before it is called it could be wise to put in the <head> section as like

<html>
<head>
<title>tips and technic of computer and internet</title>
<script language=”javascript” type=”text/javascript”>
function displaymessage()
{
alert(“hello netnic”)
}
</script>
</head>
<body>
<form>
<input type=”button value=”click me” onclick=”displaymessage()”>
</form>
</body>
</html>

out put of this program

Leave a Reply

Your email address will not be published. Required fields are marked *