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!

Passing a parameter into a subroutine

Status
Not open for further replies.

Albuckj2

Programmer
Jan 7, 2003
68
GB
I have a drop down menu, and when the user selects an option, I need to call a vbscript subroutine, with a certain parameter attached. I thought that the syntax for a passing a parameter to a subroutine was as follows:

CallAnotherSub x

And then the subroutine is:

Sub CallAnotherSub (var1)

I have tried to implement this in the following way:

<%
dim tempvar
tempvar = 3
%>

<select name=&quot;sortList&quot; style=&quot;width:180px;&quot; onChange=&quot;sortFunc tempvar&quot;>

Then my subroutine looks like:

<script type=&quot;text/vbscript&quot;>
sub sortFunc(var1)
msgbox &quot;newURL is currently &quot; + var1
end sub
</script>

However, the message box doesn’t display it. What is the problem?????
 
It sounds like you are trying to process your script client side so you may have to use JavaScript instead of VBScript Maybe something like this:

<script type=&quot;text/javascript&quot;>
function sortFunc(url)
{
alert(&quot;newURL is currently &quot; + url)
}
</script>

<select name=&quot;sortList&quot; style=&quot;width:180px;&quot; onclick=&quot;sortFunc(url)&quot;>
 
Looks to me like you're trying to have client-side script call a subroutine that only exists at the server.

Or maybe your client-side script is calling a client subroutine and trying to pass a variable that only exists at the server?

Sorry, it doesn't work that way. The client can only use what it has.
 
dilettante - you are right. I am trying to access the variable tempvar, which is only available on the server.

My problem is that the variable needs to be created on the server, but available for the client when a user changes the select box. The variable can't be constructed on the client side because it doesn't have access to the correct variables. How on earth can I do this????

I thought one possible way was to create a hidden element of a form, and populate the value of that with this string, so that I could access it on the server side. But I've tried the following in the code and it doesn't work....


<form name=&quot;sortTabForm&quot;>
<input type=&quot;hidden&quot; name=&quot;tempy&quot; value=&quot;na&quot;>
<% document.sortTabForm.tempy.value = &quot;the string&quot; %>
<select name=&quot;sortList&quot; style=&quot;width:180px;&quot; onChange=&quot;sorting(document.sortTabForm.tempy.value)&quot;>
 
Maybe something like:

<%
dim tempvar
tempvar = 3
%>

<select name=&quot;sortList&quot; style=&quot;width:180px;&quot; onChange=&quot;sortFunc <%= tempvar %>&quot;>

This assume that by the time the client page is built and sent to the browser
Code:
tempvar
is well known and a fixed value of course - at least for that particular round-trip.

In general you might get a better response on this over in the ASP Forum though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top