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

T

thisis

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

Mike Brind

thisis said:
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.
 
T

Tim Slattery

thisis said:
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.
 
A

Anthony Jones

thisis said:
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.
 
T

Tim Slattery

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

Anthony Jones

Tim Slattery said:
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.
 
T

thisis

Anthony said:
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?
 
T

thisis

Anthony said:
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?
 
A

Anthony Jones

thisis said:
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?
 
T

thisis

Anthony said:
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.
 
A

Anthony Jones

thisis said:
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.
 
T

thisis

Anthony said:
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/asp_script_runat_vs_render_blocks.htm
 
T

thisis

Anthony said:
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?
 
A

Anthony Jones

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/asp_script_runat_vs_render_blocks.htm

This isn't applicable in the case where the VBS file contains only a set of
functions.
 
A

Anthony Jones

thisis said:
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.
 
T

thisis

Anthony said:
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.


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" -->
%>
 
A

Anthony Jones

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

thisis

Anthony said:
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
%>
 
T

thisis

Anthony said:
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
%>
 
A

Anthony Jones

thisis said:
Anthony said:
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 |

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").innerHTML = "3 + 4 = " &
DoSomething(3,4)
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top