User Defined Functions
In many respects, the reasons for developing your own functions are essentially the same as for using built-in functions. Probably ,the main reason for developing functions boils down to
Using functions can also help code debugging and development because particular functionalities are more segmented and it is usually easier to develop and debug smaller segments.
Basic Function Syntax. There are some rules that must be followed with respect to naming functions and their overall layout.
<title>Determining Display Size</title>
var screen_height = window.screen.availHeight;
var screen_width = window.screen.availWidth;
window.document.write("<P>The screen height is " + screen_height + " pixels.</P>");
window.document.write("<P>The screen width is " + screen_width + " pixels</P>");
<body bgcolor = "990000" link ="cccccc" vlink="cccccc">
<a href="#" onClick="getScreenSize(); return false;">
<font size=5><b>Click here to get your screen size</b></font></a>
|Notice how I have placed the function in the header
section of the page. It is invoked when the link is clicked.
When you upload and access the page you should see the following with the link.
|After clicking on the link you are likely to see something like the following. Obviously, my taskbar at the bottom is taking away a little bit of my display area.|
|The next page will start to involve slightly more sophisticated functions where we pass in arguments and pass the results of the function back to the calling routine.|