VBScript Placement in HTML File
VBScript Placement in HTML File
vbscript placement i html |
We place VBScript code anywhere in an HTML document. But the most used way to include VBScript in your HTML code is as follows −
·
Script in <head>...</head> section part.
·
Script in <body>...</body> section part.
·
Script in <body>...</body> and
<head>...</head> sections part.
·
Script in an external file and then include in
<head>...</head> section part.
In the following
part, we will see how we can write VBScript in different ways :
1.
VBScript in
<head>...</head> section part :
If you want to your script run on any some event then we write script in
head section, such as when a user clicks button, form anywhere, then you will
place that script in the head as follows −
Hello public, how are you
<!DOCTYPE html>
<html>
<body>
<p id="demo" onclick="myFunction()"> <input type = "button"
onclick = "Hello()" value = "Hello" /></p>
<script>
function myFunction()
{
document.getElementById("demo").innerHTML = "hello
public,How are you";
}
</script>
</body>
</html>
|
It will be produce the following
output − A button with the name Hello. When we click on the Button, the message
box is displayed to the user with the message " hello public,How are you
".
Before click :
After click on button :
2.VBScript in <body>...</body> section part :
If you have to run your script as the page load so that the script
generates result in the page, the script goes in the <body> section of
the document. In this case, you would not have any function defined using
Script −
<!DOCTYPE
html>
<html>
<body>
<h2>Script in
Body</h2>
<p
id="hello">Hello </p>
<button
type="button" onclick="myFunction()">Click
me</button>
<script>
function
myFunction()
{
document.getElementById("hello").innerHTML = "By .";
}
</script>
</body>
</html>
|
This
will produce the following output −
3.External File as VBScript:
Some time we want
to write multiple line of vbscript to run nay page ,but it is not so easy to
manage it. That time we use another file for script and connect with your main
file by using script tag.
<html>
<head>
<script type = "text/vbscript" src = "filename.vbs" ></script>
</head>
<body>
//body
</body>
</html>
|
TO use script from
an external file source you want to write your scropt in simple text file with
“ .vbs” extension. Then include that file as above sample code.
No comments: