Re: How do i call a function defined in html script tags from asp page? by thisis
thisis
Thu Nov 02 10:05:37 CST 2006
Anthony Jones wrote:
> "thisis" <helloOne@web.de> wrote in message
> news:1162381569.185529.239290@e3g2000cwe.googlegroups.com...
> > Hi All,
> >
> > i have this.asp page:
> >
> > <script type="text/vbscript">
> > Function myFunc(val1ok, val2ok)
> > ' do something ok
> > myFunc = " return something ok"
> > End Function
> > </script>
> >
> > <html>
> > <body>
> > <%
> > val1ok = something1
> > val2ok = something2
> > thenewVal = myFunc((val1ok), (val2ok))
> > %>
> > </body>
> > </html>
> >
> > i want to call and use the returned value of Function myFunc(val1ok,
> > val2ok) ,
> >
> > without omitting the html script tags and replacing them in <% %>,
> >
> > (My Question is:)
> >
> > How do i call a function defined in html script tags from asp page?
> >
>
> If you have a set of functions you want to share with the client and the
> server place the functions in a VBS file. Take this example Test.vbs:-
>
> Function DoSomething(a, b)
> DoSomething = a + b
> End Function
>
> Note that since this is a vbs file it does not contain <%%>
>
> Now here is an example page that consumes the function both server side and
> client side:-
>
> <script src="test.vbs" runat="server" language="vbscript"></script>
> <html>
> <script src="test.vbs" type="text/vbscript"></script>
> <script type="text/vbscript">
> Function Body_Onload()
> divLocal.innerHTML = "3 + 4 = " & DoSomething(3,4)
> End Function
> </script>
> <body onload="Body_Onload()">
> 1 + 2 = <%=DoSomething(1,2)%>
> <div id="divLocal" />
> </body>
> </html>
>
> Anthony.
Hi Anthony Jones,
i tried to run your sample code in a couple of run time test
combination.
on some cases i got errors, which i don't understand why the errors
where "produced"?
for example:
case run test 1
==============
the test.vbs:
Function DoSomething(a, b)
DoSomething = a + b
End Function
the test.asp:
1 <script src="test.vbs" runat="server" language="vbscript"></script>
2 <html>
3 <body>
4 3 + 4 = <%=DoSomething(3,4)%>
5 </body>
6 </html>
ie result:
3 + 4 =
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'DoSomething'
/dt/test.asp, line 4
My Question:case run test 1
it seems that the script test.vbs runs on the server,
because: script src="test.vbs" runat="server" ok.
and, it seems that the test.asp code line runs on the server too,
because: <% %> is in the .asp page
So, Why do I get the Type mismatch: 'DoSomething' error?