Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling vbscript from ASP

Status
Not open for further replies.

nuVBer

Programmer
Jul 6, 2001
63
US
I have an asp page that requests variables from a posting asp page. In the requesting page I am trying to call a function that is client side vbscript, but the asp code can't recognize it. How do I get it to see the function?

Code is something like this:

<% 'create SQL string from posting asp
asp code here
Call vbFunction(sql)
%>

<script language=vbscript>
function vbFunction(sql)
'vb code here
end function
</script>


The error I get is : Variable is undefined: 'vbFunction'


 
That is not the way ASP works. An ASP page does not request variables from a posting page. An ASP finds data that was sent to it from a browser; the data could be in the querystring or in the POSTed data. The POSTed data is in the message which the browser sends to the server; the message sent by the browser is called a Request message; the data is sent in the Request body. That data is passed along to the ASP script and we access the data using the Request object; for example, creditCardNumber = Request.Form(&quot;credit_card_number&quot;).Item().

It may be useful to stop thinking about ASP pages, there is no such thing as an ASP page. There are ASP scripts which generate HTML that is sent to a browser to render as a web page. Call that the HTML page. There is no way that an ASP script can call a function in the HTML page on the browser.

What you must do is pass data between the scripts in the HTML page on the browser and the ASP script on the server. Put the vbFunction in the ASP script, and give it the data it needs from the HTML page. The browser sends the data either in the querystring part of a URL, a link or form action; or in the Request body which consists of the data in form fields that are submitted to the server. Use hidden fields to send data that the person viewing the web page is not providing. That data is retrieved from the Request object by the ASP script.

For more specific help tell us what you are trying to do rather than how you have tried to do it (because as I said it can't be done that way.)
 
I have tried what you suggest, but it doesn't work because I have to have the SQL string I build in the client. Let me backup...I have an intranet page that allows users to select options that are passed to another page (asp also) that is used to query a SQL Server db. I want to present those records in an OWC spreadsheet. When I keep all script in the asp script, it doesn't recognize the web component. When I use a separate vb function it recognizes the web component, but won't recognize the funtion. It's a catch 22. Anyone have any suggestions?
 
try to use response.write(&quot;here write client vbscript that will run your function&quot;).
Just an idea, haven't test it.
 
OK, tried that, but it didn't work either. Thanks
 
when you use
Call VBFunction (sql)
asp will call server-side function.

I think you should use like this (not tested)

<% 'create SQL string from posting asp
'asp code here
sql = &quot;This is my sql&quot;
%>

<head>
<script language=vbscript>
function vbFunction(<%=sql%>)
'vb code here
end function
</script>
</head>
<body>
some HTML code here
</body>


 
Thanks, I tried that too, but the vbscript doesn't recognize the <%=sql%>. I suppose since it is in the <vbscript> </vbscript> tags.
 
This is not exactly what you want, but this is an example that you can pass ASP variable to a client-side JavaScript.
I tested.

page1.asp

<head>
</head>
<body>
<form action=&quot;page2.asp&quot; method=&quot;POST&quot;>
<input type=&quot;text&quot; name=&quot;s&quot; value=&quot;This is my sql&quot;>
<input type=&quot;submit&quot;>
</form>

</body>

================================
page2.asp
<%
Dim sql
sql = Request.Form(&quot;s&quot;)

%>

<head>

</head>

<body>

<SCRIPT LANGUAGE=&quot;VBScript&quot;>
Sub Window_onLoad
MsgBox(&quot;<%=sql%>&quot;)
End Sub
</SCRIPT>

</body>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top