By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,666 Members | 1,784 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,666 IT Pros & Developers. It's quick & easy.

How do i call a function defined in html script tags from asp page?

P: n/a
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?

Nov 1 '06 #1
Share this Question
Share on Google+
19 Replies


P: n/a
"thisis" <he******@web.dewrote in message
news:11**********************@e3g2000cwe.googlegro ups.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?
You can't call client-side code from server-side code. Nor vice-versa.
Full stop.

--
Mike Brind
Nov 1 '06 #2

P: n/a
"thisis" <he******@web.dewrote:
>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?
You don't. The ASP code runs on the server, producing HTML as output.
When the ASP code finishes, the resulting HTML is sent to the client.
The client's browser parses it, finding the Javascript code (among
other things). Since the server-side ASP function has finished and is
*not* sent to the client, the client-side Javascript cannot call it.
It doesn't exist any more by the time the Javascript code runs.

--
Tim Slattery
MS MVP(DTS)
Sl********@bls.gov
Nov 1 '06 #3

P: n/a

"thisis" <he******@web.dewrote in message
news:11**********************@e3g2000cwe.googlegro ups.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.
Nov 1 '06 #4

P: n/a
"Anthony Jones" <An*@yadayadayada.comwrote:

>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>
That will work, but only with IE. Anybody using FireFox, Mozilla,
Opera, Netscape, or any other non-MS browser won't be able to use the
page.

--
Tim Slattery
MS MVP(DTS)
Sl********@bls.gov
Nov 1 '06 #5

P: n/a

"Tim Slattery" <Sl********@bls.govwrote in message
news:eb********************************@4ax.com...
"Anthony Jones" <An*@yadayadayada.comwrote:

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>

That will work, but only with IE. Anybody using FireFox, Mozilla,
Opera, Netscape, or any other non-MS browser won't be able to use the
page.
True but the OP started off with VBScript already being sent to the client
as it was so clearly IE is the target.
>
--
Tim Slattery
MS MVP(DTS)
Sl********@bls.gov

Nov 1 '06 #6

P: n/a

Anthony Jones wrote:
"thisis" <he******@web.dewrote in message
news:11**********************@e3g2000cwe.googlegro ups.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 attemped to run your sample in couple on run test combinations.

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>

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,
and the the test.asp code line runs on the server too.

So, Why do I get the Type mismatch: 'DoSomething' error?

Nov 2 '06 #7

P: n/a

Anthony Jones wrote:
"thisis" <he******@web.dewrote in message
news:11**********************@e3g2000cwe.googlegro ups.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?

Nov 2 '06 #8

P: n/a

"thisis" <he******@web.dewrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
>
Anthony Jones wrote:
"thisis" <he******@web.dewrote in message
news:11**********************@e3g2000cwe.googlegro ups.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?
You would get this error if a test.vbs existed in the /dt folder but it
didn't have the DoSomething function in it.

Are you sure you've saved the vbs file?

Nov 2 '06 #9

P: n/a

Anthony Jones wrote:
"thisis" <he******@web.dewrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...

Anthony Jones wrote:
"thisis" <he******@web.dewrote in message
news:11**********************@e3g2000cwe.googlegro ups.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?

You would get this error if a test.vbs existed in the /dt folder but it
didn't have the DoSomething function in it.

Are you sure you've saved the vbs file?
Hi Anthony Jones ,

both files test.vbs & test.asp are in the same folder/directory.

Nov 2 '06 #10

P: n/a

"thisis" <he******@web.dewrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
>
Anthony Jones wrote:
"thisis" <he******@web.dewrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
>
Anthony Jones wrote:
"thisis" <he******@web.dewrote in message
news:11**********************@e3g2000cwe.googlegro ups.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?
>
You would get this error if a test.vbs existed in the /dt folder but it
didn't have the DoSomething function in it.

Are you sure you've saved the vbs file?

Hi Anthony Jones ,

both files test.vbs & test.asp are in the same folder/directory.
What server are you using. Works fine on IIS5.0 Win2K ans IIS5.1 XP Pro.If
on IIS6 there might be security thing that needs loosening.
Nov 2 '06 #11

P: n/a

Anthony Jones wrote:
"thisis" <he******@web.dewrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...

Anthony Jones wrote:
"thisis" <he******@web.dewrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...

Anthony Jones wrote:
"thisis" <he******@web.dewrote in message
news:11**********************@e3g2000cwe.googlegro ups.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?

>
You would get this error if a test.vbs existed in the /dt folder but it
didn't have the DoSomething function in it.
>
Are you sure you've saved the vbs file?
Hi Anthony Jones ,

both files test.vbs & test.asp are in the same folder/directory.

What server are you using. Works fine on IIS5.0 Win2K ans IIS5.1 XP Pro.If
on IIS6 there might be security thing that needs loosening.
Hi Anthony Jones,

i'm using a "small" version of iis, pws 4.0 win98/add0n.
there is no tighten security.

it's reads odd that on one ms server as yours, and on other server as
mine,
the code behaves diffrently.

i think, if the code was proper the issue wouldn't come up.

i run into this article which i thibk is valid for my topic:

http://www.exodus-dev.com/techtips/a...der_blocks.htm

Nov 3 '06 #12

P: n/a

Anthony Jones wrote:
"thisis" <he******@web.dewrote in message
news:11**********************@e3g2000cwe.googlegro ups.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 (again today),

i managed to run your sample code with a slight changes.

in the test.asp
i replaced the first line in your sample, yourLine:
<script src="test.vbs" runat="server" language="vbscript"></script>
with thisLine:
<!-- #include file = test.inc -->

the new test.asp :

<!-- #include file = test.inc -->
<script src="test.vb" 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>
and i added a new file test inc:
<%
Function DoSomething(a, b)
DoSomething = a + b
End Function
%>

the code runs with no errors.

but damm, i was trying to avoid using <% %in the first place.
that's issue returns me again to the starting point of this topic
thread.
(reminder):

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?

Nov 3 '06 #13

P: n/a
>
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?
>

You would get this error if a test.vbs existed in the /dt folder but
it
didn't have the DoSomething function in it.

Are you sure you've saved the vbs file?
>
Hi Anthony Jones ,
>
both files test.vbs & test.asp are in the same folder/directory.
>
What server are you using. Works fine on IIS5.0 Win2K ans IIS5.1 XP
Pro.If
on IIS6 there might be security thing that needs loosening.

Hi Anthony Jones,

i'm using a "small" version of iis, pws 4.0 win98/add0n.
there is no tighten security.

it's reads odd that on one ms server as yours, and on other server as
mine,
the code behaves diffrently.

i think, if the code was proper the issue wouldn't come up.

i run into this article which i thibk is valid for my topic:

http://www.exodus-dev.com/techtips/a...der_blocks.htm
This isn't applicable in the case where the VBS file contains only a set of
functions.
Nov 3 '06 #14

P: n/a

"thisis" <he******@web.dewrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
>
Anthony Jones wrote:
"thisis" <he******@web.dewrote in message
news:11**********************@e3g2000cwe.googlegro ups.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 (again today),

i managed to run your sample code with a slight changes.

in the test.asp
i replaced the first line in your sample, yourLine:
<script src="test.vbs" runat="server" language="vbscript"></script>
with thisLine:
<!-- #include file = test.inc -->

the new test.asp :

<!-- #include file = test.inc -->
<script src="test.vb" 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>
and i added a new file test inc:
<%
Function DoSomething(a, b)
DoSomething = a + b
End Function
%>
That just defeats the whole point of what you were trying to do. You only
want to have the VBScript code in one place. If you need to change
something in test.vbs you now need to replicate the change in test.inc. I
don't have access to Win98/PWS to test this but it doesn't surprise me that
it has different behaviour. I suspect it doesn't support the runat="server"
attribute.
the code runs with no errors.

but damm, i was trying to avoid using <% %in the first place.
that's issue returns me again to the starting point of this topic
thread.
(reminder):

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?
Without runat="server" support? I can't see how you can.

You might try this:-

<%
<!-- #include file="test.vbs" -->
%>
<html>
<body>
3 + 4 = <%=DoSomething(3,4)%>
</body>
</html>

It doesn't work in IIS but you never know, perhaps you can get away with it
in PWS.
Nov 3 '06 #15

P: n/a

Anthony Jones wrote:
"thisis" <he******@web.dewrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...

Anthony Jones wrote:
"thisis" <he******@web.dewrote in message
news:11**********************@e3g2000cwe.googlegro ups.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 (again today),

i managed to run your sample code with a slight changes.

in the test.asp
i replaced the first line in your sample, yourLine:
<script src="test.vbs" runat="server" language="vbscript"></script>
with thisLine:
<!-- #include file = test.inc -->

the new test.asp :

<!-- #include file = test.inc -->
<script src="test.vb" 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>
and i added a new file test inc:
<%
Function DoSomething(a, b)
DoSomething = a + b
End Function
%>

That just defeats the whole point of what you were trying to do. You only
want to have the VBScript code in one place. If you need to change
something in test.vbs you now need to replicate the change in test.inc. I
don't have access to Win98/PWS to test this but it doesn't surprise me that
it has different behaviour. I suspect it doesn't support the runat="server"
attribute.
the code runs with no errors.

but damm, i was trying to avoid using <% %in the first place.
that's issue returns me again to the starting point of this topic
thread.
(reminder):

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?

Without runat="server" support? I can't see how you can.

You might try this:-

<%
<!-- #include file="test.vbs" -->
%>
<html>
<body>
3 + 4 = <%=DoSomething(3,4)%>
</body>
</html>

It doesn't work in IIS but you never know, perhaps you can get away with it
in PWS.
Hi Anthony Jones,

(btw - pws does support runat="server", don't blame the machine for our
lack of skills)
this line, will not work, it is not a valid line in asp rules.
the reason for that, is :
the following script will not work because ASP executes the #include
directive before it assigns a value to the variable.
ref: [http://www.w3schools.com/asp/asp_incfiles.asp]

<%
<!-- #include file="test.vbs" -->
%>

Nov 3 '06 #16

P: n/a
>
Hi Anthony Jones,

(btw - pws does support runat="server", don't blame the machine for our
lack of skills)

So if runat server is supported in PWS then the example I gave should work.

If I go through these steps exactly (can you follow them verbatim?) :-

Create a file called test.vbs in a folder (lets also call it test) under the
root folder of the local website:-

Function DoSomething(a, b)
DoSomething = a + b
End Function

Now in the same folder I create test.asp that has this content:-

<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>

Now in IE6 I visit http://localhost/test/test.asp

I see:-

1 + 2 = 3
3 + 4 = 7

but you get a type mismatch when excuteing DoSomething in <% %>. Which
indicates that the DoSomething function hasn't been created. If that's how
PWS (which is ASP 2.0) works there is little point in it supporting the
runat="server" attribute.

this line, will not work, it is not a valid line in asp rules.
the reason for that, is :
the following script will not work because ASP executes the #include
directive before it assigns a value to the variable.
ref: [http://www.w3schools.com/asp/asp_incfiles.asp]

<%
<!-- #include file="test.vbs" -->
%>
Oh well it was a longshot based on the apparently the PWS not doing exactly
what I see in an IIS implementation.
Nov 3 '06 #17

P: n/a

Anthony Jones wrote:

Hi Anthony Jones,

(btw - pws does support runat="server", don't blame the machine for our
lack of skills)

So if runat server is supported in PWS then the example I gave should work.

If I go through these steps exactly (can you follow them verbatim?) :-

Create a file called test.vbs in a folder (lets also call it test) under the
root folder of the local website:-

Function DoSomething(a, b)
DoSomething = a + b
End Function

Now in the same folder I create test.asp that has this content:-

<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>

Now in IE6 I visit http://localhost/test/test.asp

I see:-

1 + 2 = 3
3 + 4 = 7

but you get a type mismatch when excuteing DoSomething in <% %>. Which
indicates that the DoSomething function hasn't been created. If that's how
PWS (which is ASP 2.0) works there is little point in it supporting the
runat="server" attribute.

this line, will not work, it is not a valid line in asp rules.
the reason for that, is :
the following script will not work because ASP executes the #include
directive before it assigns a value to the variable.
ref: [http://www.w3schools.com/asp/asp_incfiles.asp]

<%
<!-- #include file="test.vbs" -->
%>

Oh well it was a longshot based on the apparently the PWS not doing exactly
what I see in an IIS implementation.

Hi Anthony Jones,
i did exactly what you worte word by word:

1. i created the file test.asp with the relevant code.
2. i created the file test.vbs , in the same folder of step 1, with the
relevant code.
3. i rechecked that my pws supports <script runat="server" ...>, and it
does - i've an app that uses <script runat="server" ...>.
4. i rechecked that there are no security issues, and there are no
security on my pws.
5. i "mapped" the relevant virtual folder, and the results are i) & ii)

i)
on the ie 6.0 window i get:
-------------------------------------------------
| 1 + 2 = |
| |
| Microsoft VBScript runtime error '800a000d' |
| |
| Type mismatch: 'DoSomething' |
| |
| /dt/test.asp, line 10 |
-------------------------------------------------

ii)
on the ie 6.0 error message box -
- see ie menu tools/internet options/advanced/enable script error
notify... -

i get this:
---------------------------------------
| Line: 6 |
| Char: 2 |
| Error: Object required: 'divLocal' |
| Code: 0 |
| URL: http:/127.0.0.1/dt/test.asp |
---------------------------------------

So you susspect that my pws does not support the runat="server" solemn
attribute.

On my global.asa i use this attribute,

<script language="VBScript" runat="Server">
Sub Application_OnStart
</script>
<script language="VBScript" runat="Server">
<!-- #include file="incs/globalasa/globApsOSDefault.inc" -->
</script>

<script language="VBScript" runat="Server">
END Sub
</script>

<script language="VBScript" runat="Server">
Sub Application_OnEnd
</script>
<script language="VBScript" runat="Server">
<!-- #include file="incs/globalasa/globApsOEDefault.inc" -->
</script>

<script language="VBScript" runat="Server">
END Sub
</script>
(end of global.asa)
and for instance, on globApsOSDefault.inc:

<script language="VBScript" runat="Server">
' set application variables requires reboot
Application("countVisitors") = 0
Application("dateAppStarted") = now()
</script>

i think, correct me if i'm worng, that my pws does support
runat="Server",
but does not support functions defined in this manner of syntex:
<script runat="server" src="test.vbs" language="vbscript"></script>

a. what do you think, what other options have i got to get a valid run
of the line:
<script src="test.vbs" runat="server" language="vbscript"
type="text/vbscript">?
b. is the code line:
<script runat="server" language="vbscript" type="text/vbscript">
<!-- #include file = "test.inc" -->
</script>
is equal to:
<script src="test.vbs" runat="server" language="vbscript"></script>
regarding the order of execution and running the code on the server?
test.inc:
<%
Function DoSomething(a, b)
DoSomething = a + b
End Function
%>

Nov 4 '06 #18

P: n/a

Anthony Jones wrote:

Hi Anthony Jones,

(btw - pws does support runat="server", don't blame the machine for our
lack of skills)

So if runat server is supported in PWS then the example I gave should work.

If I go through these steps exactly (can you follow them verbatim?) :-

Create a file called test.vbs in a folder (lets also call it test) under the
root folder of the local website:-

Function DoSomething(a, b)
DoSomething = a + b
End Function

Now in the same folder I create test.asp that has this content:-

<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>

Now in IE6 I visit http://localhost/test/test.asp

I see:-

1 + 2 = 3
3 + 4 = 7

but you get a type mismatch when excuteing DoSomething in <% %>. Which
indicates that the DoSomething function hasn't been created. If that's how
PWS (which is ASP 2.0) works there is little point in it supporting the
runat="server" attribute.

this line, will not work, it is not a valid line in asp rules.
the reason for that, is :
the following script will not work because ASP executes the #include
directive before it assigns a value to the variable.
ref: [http://www.w3schools.com/asp/asp_incfiles.asp]

<%
<!-- #include file="test.vbs" -->
%>

Oh well it was a longshot based on the apparently the PWS not doing exactly
what I see in an IIS implementation.

Hi Anthony Jones,
i did exactly what you worte word by word:

1. i created the file test.asp with the relevant code.
2. i created the file test.vbs , in the same folder of step 1, with the
relevant code.
3. i rechecked that my pws supports <script runat="server" ...>, and it
does - i've an app that uses <script runat="server" ...>.
4. i rechecked that there are no security issues, and there are no
security on my pws.
5. i "mapped" the relevant virtual folder, and the results are i) & ii)

i)
on the ie 6.0 window i get:
-------------------------------------------------
| 1 + 2 = |
| |
| Microsoft VBScript runtime error '800a000d' |
| |
| Type mismatch: 'DoSomething' |
| |
| /dt/test.asp, line 10 |
-------------------------------------------------

ii)
on the ie 6.0 error message box -
- see ie menu tools/internet options/advanced/enable script error
notify... -

i get this:
-----------------------------------------
| Line: 6 |
| Char: 2 |
| Error: Object required: 'divLocal' |
| Code: 0 |
| URL: http:/127.0.0.1/dt/test.asp |
-----------------------------------------

So you susspect that my pws does not support the runat="server" solemn
attribute.

On my global.asa i use this attribute,

<script language="VBScript" runat="Server">
Sub Application_OnStart
</script>
<script language="VBScript" runat="Server">
<!-- #include file="incs/globalasa/globApsOSDefault.inc" -->
</script>

<script language="VBScript" runat="Server">
END Sub
</script>

<script language="VBScript" runat="Server">
Sub Application_OnEnd
</script>
<script language="VBScript" runat="Server">
<!-- #include file="incs/globalasa/globApsOEDefault.inc" -->
</script>

<script language="VBScript" runat="Server">
END Sub
</script>
(end of global.asa)
and for instance, on globApsOSDefault.inc:

<script language="VBScript" runat="Server">
' set application variables requires reboot
Application("countVisitors") = 0
Application("dateAppStarted") = now()
</script>

i think, correct me if i'm worng, that my pws does support
runat="Server",
but does not support functions defined in this manner of syntex:
<script runat="server" src="test.vbs" language="vbscript"></script>

a. what do you think, what other options have i got to get a valid run
of the line:
<script src="test.vbs" runat="server" language="vbscript"
type="text/vbscript">?
b. is the code line:
<script runat="server" language="vbscript" type="text/vbscript">
<!-- #include file = "test.inc" -->
</script>
is equal to:
<script src="test.vbs" runat="server" language="vbscript"></script>
regarding the order of execution and running the code on the server?
test.inc:
<%
Function DoSomething(a, b)
DoSomething = a + b
End Function
%>

Nov 4 '06 #19

P: n/a

"thisis" <he******@web.dewrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>
Anthony Jones wrote:
>
Hi Anthony Jones,
>
(btw - pws does support runat="server", don't blame the machine for
our
lack of skills)
>
>
So if runat server is supported in PWS then the example I gave should
work.

If I go through these steps exactly (can you follow them verbatim?) :-

Create a file called test.vbs in a folder (lets also call it test) under
the
root folder of the local website:-

Function DoSomething(a, b)
DoSomething = a + b
End Function

Now in the same folder I create test.asp that has this content:-

<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>

Now in IE6 I visit http://localhost/test/test.asp

I see:-

1 + 2 = 3
3 + 4 = 7

but you get a type mismatch when excuteing DoSomething in <% %>. Which
indicates that the DoSomething function hasn't been created. If that's
how
PWS (which is ASP 2.0) works there is little point in it supporting the
runat="server" attribute.

this line, will not work, it is not a valid line in asp rules.
the reason for that, is :
the following script will not work because ASP executes the #include
directive before it assigns a value to the variable.
ref: [http://www.w3schools.com/asp/asp_incfiles.asp]
>
<%
<!-- #include file="test.vbs" -->
%>
>
Oh well it was a longshot based on the apparently the PWS not doing
exactly
what I see in an IIS implementation.


Hi Anthony Jones,
i did exactly what you worte word by word:

1. i created the file test.asp with the relevant code.
2. i created the file test.vbs , in the same folder of step 1, with the
relevant code.
3. i rechecked that my pws supports <script runat="server" ...>, and it
does - i've an app that uses <script runat="server" ...>.
4. i rechecked that there are no security issues, and there are no
security on my pws.
5. i "mapped" the relevant virtual folder, and the results are i) & ii)

i)
on the ie 6.0 window i get:
-------------------------------------------------
| 1 + 2 = |
| |
| Microsoft VBScript runtime error '800a000d' |
| |
| Type mismatch: 'DoSomething' |
| |
| /dt/test.asp, line 10 |
-------------------------------------------------
The above output shows that the clientside function isn't working.

The runat server is working.
>
ii)
on the ie 6.0 error message box -
- see ie menu tools/internet options/advanced/enable script error
notify... -

i get this:
---------------------------------------
| Line: 6 |
| Char: 2 |
| Error: Object required: 'divLocal' |
| Code: 0 |
| URL: http:/127.0.0.1/dt/test.asp |
---------------------------------------

So you susspect that my pws does not support the runat="server" solemn
attribute.
It's the clientside that doesn't appear to be working in this case.

Try this for the body_onload function (keep everything as I've specified)

Function Body_Onload()
window.divLocal.innerHTML = "3 + 4 = " & DoSomething(3,4)
End Function

Other variations:-

Function Body_Onload()
document.getElementById("divLocal").innerHTML = "3 + 4 = " &
DoSomething(3,4)
End Function

Function Body_Onload()
window.document.getElementById("divLocal").innerHT ML = "3 + 4 = " &
DoSomething(3,4)
End Function
Nov 5 '06 #20

This discussion thread is closed

Replies have been disabled for this discussion.