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!

How to pass value from vbscirpt to ASP???

Status
Not open for further replies.

SuperCyber

Programmer
Aug 10, 2001
35
US
I have a client side vbscript that returns the value for the selected dropdown item. I want to pass the value to a function that will run a stored procedure and return the values to the web page, but I cant get the value to pass to the function properly. I tried putting the RUNAT=Server in the script tag but no I cant pass the value. Any ideas??

Thanks,
Brian
 
Client variables and server variables cannot read each other in the method you described. You're going to have to use request variables via the URL or through form processing. Set the VBScript variable to put put in a form, and directed to another page, then call it by doing a: Request("VariableName")

dan
 
is there a way to post a value back to the same page without reloading the page?
 
You can write functions in ASP similar to the way you write them in VisualBASIC. It is good programming practice to use functions to modularize your code and to better provide reuse. To declare a subroutine (a function that returns no value), you simply type:


<%@ LANGUAGE=&quot;VBSCRIPT&quot; %>
<%
sub SubroutineName( Parameters to Pass In )
'Code for Sub...
end sub
%>
A function differs from a subroutine in the fact that it returns data. To declare a function, the syntax is similar:


<%@ LANGUAGE=&quot;VBSCRIPT&quot; %>
<%
function FunctionName( Parameters to Pass In )
'Code for Function...
end function
%>
Let's look at the code for a function that takes an integer value and returns the square of that value. Also included is code to call the function.


<%@ LANGUAGE=&quot;VBSCRIPT&quot; %>
<%
function Square(num)
Square = num * num end function


'Returns 25
Response.Write(Square(5))

'Should print &quot;40 is less than 8^2&quot;
if 40 < Square(8) then
Response.Write(&quot;40 is less than 8^2&quot;)
else
Response.Write(&quot;8^2 is less than 40&quot;)
end if
%>
If you do not understand an if statement, this tutorial should help!

To return a value from a function, you need to say the function's name = some value. That value is what is returned. In this case, we are returning num (the number passed in) times itself, or essentially num^2.

Important! Whenever you call a function and expect it to return a value, you must use parenthesis to pass in the parameter(s). For example, we used Square(8). If you are calling a subroutine, you cannot use parenthesis. If we want to pass in value(s), we need to put a space after the sub name and then each parameter separated by a comma. Observe the example below:


<%@ LANGUAGE=&quot;VBSCRIPT&quot; %>
<%
sub PrintProfit(Revenue, Overhead, COGS, Admin)
'Create a variable to store our profit
Dim Profit

Profit = CDbl(Revenue - (Overhead + COGS + Admin))

Response.Write(&quot;$&quot; & Profit)
end sub


'Call the sub with various values
'Will output $100.0
PrintProfit 150, 25, 10, 15

'Will output $0.5 (a bad year!!)
PrintProfit 200, 150, 45, 4.5
%>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top