VBScript placement

Example

Functions in the head section
You can place the script in the head section. Often, we place all the functions in the head section. The purpose of this is to ensure that the functions have been loaded before they are called.
Scripts in the body section
This example will execute a script placed in the body section. The script in the body will be executed when the page is loaded.

Where to Place VBScript

When the page is loaded into the browser, the script in the page will be executed immediately. We do not want this to happen. Sometimes we want the script to be executed when the page is loaded, and sometimes we want these scripts to be executed when the user triggers an event.

Scripts in the head section: When the script is called, they will be executed, or the script may also be executed when some event is triggered. When we place the script in the head section, we can ensure that they have been loaded before the user uses them:

<html>
<head>
<script type="text/vbscript">
  some statements
</script>
</head>

Scripts in the body section: When the body section of the page is loaded, the script will be executed. When we place the script in the body section, it will generate the content of the page:

<html>
<head>
</head>
<body>
<script type="text/vbscript">
  some statements
</script>
</body>

Scripts in body and head sections: You can place as many scripts in the document as you want, so you can place scripts in both the body and head sections at the same time:

<html>
<head>
<script type="text/vbscript">
  some statements
</script>
</head>
<body>
<script type="text/vbscript">
  some statements
</script>
</body>