Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript 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 October 8th, 2003, 02:34 AM
Authorized User
 
Join Date: Aug 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to spraveens
Default Passing Parameters

Hi friends !!

     Iam using ASP for server side scripting and JavaScript for creating menus etc. Now My Problem Goes like This :
I pass a parameter "temp" from file1.asp to file2.asp through link
i.e.
<a href="http://localhost/file2.asp?temp=somevalue>pass param</a>

Now I receive the temp variable in file2.asp as follows :

dim temp
temp=request.querystring("temp")

Now I want to assign the value of "temp" to a variable inside javascript in file2.asp, Iam unable to receive the value bcoz I dont know the javascript equivalent of "request.querystring" ,
please help.
Praveen

 
Old October 8th, 2003, 03:13 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

There are basically two ways to do this: from the client with JavaScript, or from the server with ASP code by writing the values to the JavaScript.

Method 1:
You can use document.location.search to retrieve the entire QueryString in JavaScript. This will return the entire QueryString, including the question mark. You'll need to do some string parsing to get at the individual parameters.

Method 2 (much easier):
Use <%= temp %> to write the value of the temp var to a client side JavaScript block, like this:
Code:
<script language="JavaScript" type="text/javascript">
  var jsTemp = '<%=temp%>';
</script>
When the ASP page loads, it will dump the value for temp between the ''s in the JavaScript code block, so you end up with a valid value for your JavaScript variable.

Hope this helps,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old October 8th, 2003, 03:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

You just need to pass the variable from asp to javascript, something like this in file2.asp:
Code:
<script language="javascript" type="text/javascript">
var yourJavascriptVariable = <%=Request.QueryString("temp")%>;
...
</script>
An alternative is to use the javascript property window.location.search in file2.asp, which will give you the string "temp=something", but it seems easier to me to use the asp method.

hth
Phil
 
Old October 8th, 2003, 03:52 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Ha Phil,

Great minds think alike ;)


Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old October 8th, 2003, 06:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by Imar
 Ha Phil,

Great minds think alike ;)
Or is it "fools seldom differ"? :D
 
Old October 8th, 2003, 07:06 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

LOL, yeah, I think that's the one.... ;)


Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
passing parameters fizzerchris Access VBA 5 August 31st, 2007 12:16 PM
Passing parameters tal Ajax 5 May 26th, 2007 08:07 AM
Passing more than one parameters from datagrid Lyn ASP.NET 1.0 and 1.1 Professional 6 August 29th, 2006 02:30 AM
Passing parameters ceema Crystal Reports 0 February 15th, 2006 04:03 AM
passing parameters spraveens Javascript How-To 1 October 8th, 2003 03:14 AM





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