This question/answer comes from http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20431209.html
It provides a very good explanation of the distinction between client-side and server-side scripting in vbscript.
Hi,
I'm trying to call this VBscript:
function fnFreeze ()
for i = 0 to formA.elements.length -1
formA.elements(i).disabled = true
next
end function
under this code:
if variableA = true then
fnFreeze()
else
Response.write "No freezing done."
end if
but I keep receiving
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'fnfreeze'
can anyone advise me why, and how can I make it possible to call this function?
ok,
first I am going to assume that you want NO server side script, just client side
script:
Function fnFreeze ()
for i = 0 to formA.elements.length -1
formA.elements(i).disabled = true
next
End Function
function BodyLoad()
if variableA = true then
fnFreeze()
else
msgbox "No freezing done."
end if
end Function
<body onload="BodyLoad" language="vbscript">
....
If you want to do this server side, things get more complicated. You got to
think along the lines of server side code generating client side code which is
only executed when that code gets the client (the server side stuff is executed
at the server _first_ naturally). So here is server side mixed with client side
code.
<head>
<script type="text/vbscript">
<!--
Function fnFreeze ()
for i = 0 to formA.elements.length -1
formA.elements(i).disabled = true
next
End Function
//-->
</script>
</head>
<body language="vbscript" onload="<%if variableA = true
then %>fnFreeze()<% End If %>">
<% If Not variableA Then Response.Write "No freezing done."%>
Perhaps I should have explained at the beginning: The Response object is a
server side object. It is unfortunate that both Server Side VBScript and Client
Side VBScript are called VBScript! Server side vbscript has access to certain
objects e.g. Response, Request, Server and can create objects e.g. ADODB etcetc.
Whereas client side VBScript allows you to access the DOM and things like that.
Server Side vbscript is executed on the server so it is there that you can
access database and file systems. What a function like Response.Write does is
tell the server "Send this piece of text to the client".
Client side vbscript on the other has text
that has already been sent to the client and is now in the page on the clients
computer. The client then goes "oh look, some vbscript. lets run it."
and then the code gets executed. That's why to get a message to occur there you
use a function like msgbox which pops up. Or you can do some fancy DOM
manipulation to write the text directly into the body of the page.
A few notes:
1) If you call msgbox on the server side, the msgbox is going to pop up on the
server. Generally not a good idea unless the server is sitting on your desk and
you only want it for debug purposes.
2) Try not to use VBScript for client side code. Only the internet explorer
range of browsers support it. Use JScript or ECMAScript (Javascript, whatever)
rather (practically the same difference, just different names for the same
thing)
3) My syntax for the use of the msgbox function could be off. I don't think
there are brackets because I am calling a sub... but there might be.
Does that perhaps answer your question a bit better?
Gav