Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 11th, 2010, 10:12 AM
Registered User
 
Join Date: May 2010
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Cool VBScript body onLoad() with Parameters

Hi Forum!
I need help to write an OnLoad() function with parameters on body tag for an asp page.
The parameters are variables defined with Dim
Ex.:

%>
<SCRIPT LANGUAGE=vbscript>
<!--
Sub OpenURL(w1, w2, w3, w4)
Dim myUrl
myUrl = "prn_certified.asp?nv1=" &w1&"&nv2="&w2&"&nv3=" & w3 & "&nv4=" & w4 "&print=visible&cancel=hidden"
MsgBox myUrl, vbExclamation, "Warning"
window.open myUrl, "_blank", "fullscreen=yes,scrollbars=yes,location=no"
End Sub
-->
</SCRIPT>

<html>
<head>
<%
Dim v1, v2, v3, v4
v1 = Request("field1")
v2= Request("field2")
if v3 > 0 then
v3 = fGetFormatted(v3, Request("sort"))
else
v3 = AnotherFinction()
end if
v4 = Request("field3")
%>
</head>
<body onLoad="OpenUrl(<%=v1%>, <%=v2%> , <%=v3%> , <%=v4%>);">
</body>
</html>

I have a lot of errors, how writing the onload with parameters?
How writing the OpenURL subroutine?
Is there any data conversion to do?
Help please
 
Old May 17th, 2010, 07:45 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

You can't use parentheses when calling a SUB unless you prefix the SUB name with CALL.

So:
Code:
<body onLoad="OpenUrl <%=v1%>, <%=v2%> , <%=v3%> , <%=v4%>">
or
<body onLoad="CALL OpenUrl(<%=v1%>, <%=v2%> , <%=v3%> , <%=v4%>)">
And in any case you can't use a semicolon in VBScript code.

Oh, and on top of that, if any of v1 through v4 are not numbers, then they need "..." around them.

Probably best to do
Code:
<body onLoad='CALL OpenUrl("<%=v1%>","<%=v2%>","<%=v3%>","<%=v4%>")'>
The Following User Says Thank You to Old Pedant For This Useful Post:
NizamUlMulk (May 18th, 2010)
 
Old May 18th, 2010, 09:42 AM
Registered User
 
Join Date: May 2010
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default Thanks Viejo Pedante

That found!
Thanks A lot!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Invoke onClick() function when body onLoad muklee Javascript How-To 2 March 16th, 2007 01:02 AM
Double DB insert using body.onload needlz BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 February 20th, 2006 04:18 PM
Problems with Body onload event blaabil Javascript How-To 0 January 6th, 2006 06:45 AM
Access page parameters from vbscript jnralfe ASP.NET 1.0 and 1.1 Basics 1 September 17th, 2004 05:20 AM
Body Onload Function Question apd8x Javascript 2 July 10th, 2003 02:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.