473,396 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Passing variables from Javascript to ASP

Please help.
I use ASP and java script in my programs.
I need to read the URL direction and then store it in an ASP session object so I can read it at any time later.
I have no problem to get the URL with java using (location.href), but I just cannot find the way to pass that variable to my session object.

I already spent too much time looking for an answer to my question.
Aug 27 '07 #1
9 11441
bakpao
21
Not entirely sure with what you need and the interaction required but you can pass in the value of a texbox as a parameter for asp page.

Expand|Select|Wrap|Line Numbers
  1. <input type="button" id="cmdNextPage" class="Button" value="NextPage" 
  2. onclick="javascript:window.location='mypage.asp?ItemToSave='+document.getElementById('sometextinput').value" />
  3.  
And in mypage.asp:
Expand|Select|Wrap|Line Numbers
  1. Session("MyValue") = Request("ItemToSave")
  2.  
Aug 27 '07 #2
pbmods
5,821 Expert 4TB
Heya, Ernesto. Welcome to TSDN!

Do you need to store the URL to a session, variable, or can you use a cookie for that?
Aug 28 '07 #3
Heya, Ernesto. Welcome to TSDN!

Do you need to store the URL to a session, variable, or can you use a cookie for that?
Hi pbmods, I know I wasn't too clear in my question, but if you have a moment I'll try to explain this better; here it goes...

I have a link (not a textbox) on one ASP page that takes me to a second one
(response.write "<a href=ASP2.asp?" & (photoID) & ">Click here to go to second ASP page</a>"
this link is a field photoID in a record read from a data base, displayed as a link, and then goes back in a "for-next" loop to read the next record.

ASP2
On this second ASP page I need to read the field photoID and put it in a session object - session("photoID") -
so I thought that the easiest way to do it was by sending the userID field attached at the end of the URL and then I can extract it from the URL string.
The thing is that the variable photoID is read from a data base and displayed in a for-next loop as a link to the second ASP page, so when it finishes reading the table from the data base I only have available the last record read from the DB, and what I need is to be able to click on any photoID link displayed and somehow retrieve that photoID value.
I know I'm not so good at explaining but if you understand my problem and have a second to help me I will appreciate it very much.
Thank you,
Ernesto
Aug 28 '07 #4
pbmods
5,821 Expert 4TB
Heya, Ernesto.

So the value of the session variable depends on which link the User clicks?
Aug 28 '07 #5
Heya, Ernesto.

So the value of the session variable depends on which link the User clicks?
Hi, thank you for taking the time to write me.
Yes, the value I need to give the variable is exactly the link the user clicks.
Aug 28 '07 #6
pbmods
5,821 Expert 4TB
Heya, Ernesto.

I'm going to go ahead and move this thread to the ASP forum, where our resident Experts will be better able to help you out.
Aug 28 '07 #7
jhardman
3,406 Expert 2GB
Ernesto,

syntax for the URL with a querystring in it should be [html]<a href="ASP2.asp?photoID=234">Click here to go to second ASP page</a>"[/html]It looks like you are generating this with javascript, so I'm betting you already know enough to handle that part (putting the link in the right syntax) by yourself. Accessing the data and storing it in a session variable is very easy:
Expand|Select|Wrap|Line Numbers
  1. session("photoID") = request.querystring("photoID")
Let me know if this helps.

Jared
Aug 28 '07 #8
markrawlingson
346 Expert 100+
I have a link (not a textbox) on one ASP page that takes me to a second one
(response.write "<a href=ASP2.asp?" & (photoID) & ">Click here to go to second ASP page</a>"
this link is a field photoID in a record read from a data base, displayed as a link, and then goes back in a "for-next" loop to read the next record.
So in other words you have something like the following...

Expand|Select|Wrap|Line Numbers
  1. <%
  2. For i = 0 To AmountOfLinks
  3. %>
  4.      <a href="link1.asp?id=<%=rs("PhotoID")"%>link1</a>
  5. <%
  6. Next
  7. %>
  8.  
You want to pass PHOTOID into the session...

There's a number of ways you can do this.

If you send the PhotoID through the QueryString you could then pull it down on the next page, and simply set it into the Session.

Session("PhotoID") = Request.QueryString("PhotoId")

So if you have a set of 10 pages, put this at the top of each of them. That way, when the user clicks on any of your links, the photoid pertaining to that link is passed, pulled down on whichever page they click on, and then set into your session.

A more complicated way of doing it would be to have a hidden text field imbedded in your page that displays the links. When a user clicks one of the links a javascript could place the photoID in the text field (hidden from the user) and subsequently submit a form. On the next page you could Request.Form("iPhotoID") to retrieve it, and set it into a session variable.

An even more complicated way of doing it would be to write an AJAX function and invoke it using the OnClick event in javascript. The ajax would call an ASP script in the background and set the session id in a microfraction of a second whilst sending the user to the next page.

It depends on the scenario really.
Aug 28 '07 #9
So in other words you have something like the following...

Expand|Select|Wrap|Line Numbers
  1. <%
  2. For i = 0 To AmountOfLinks
  3. %>
  4.      <a href="link1.asp?id=<%=rs("PhotoID")"%>link1</a>
  5. <%
  6. Next
  7. %>
  8.  
You want to pass PHOTOID into the session...

There's a number of ways you can do this.

If you send the PhotoID through the QueryString you could then pull it down on the next page, and simply set it into the Session.

Session("PhotoID") = Request.QueryString("PhotoId")

So if you have a set of 10 pages, put this at the top of each of them. That way, when the user clicks on any of your links, the photoid pertaining to that link is passed, pulled down on whichever page they click on, and then set into your session.

A more complicated way of doing it would be to have a hidden text field imbedded in your page that displays the links. When a user clicks one of the links a javascript could place the photoID in the text field (hidden from the user) and subsequently submit a form. On the next page you could Request.Form("iPhotoID") to retrieve it, and set it into a session variable.

An even more complicated way of doing it would be to write an AJAX function and invoke it using the OnClick event in javascript. The ajax would call an ASP script in the background and set the session id in a microfraction of a second whilst sending the user to the next page.

It depends on the scenario really.
Thank you so much markrawlingson and jhardman for your help. My problem is solved. I was looking for an answer to my problem in the wrong place. Thanks again.
Ernesto
Aug 29 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Consuelo Guenther | last post by:
Hello, I am having problems with passing variables between pages. I have the following: First asp page has the function: -----------------------------------------------------------------------...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
5
by: Jim Banks | last post by:
Greetings I'm opening a pop up window with a html form, (in one document) and I want to pass a variable to the html form called from the hyperlink. Here's the code I'm using to pop up the...
2
by: brianwmunz | last post by:
Hi, I'm having a problem passing a variable through a URL because the variable is supposed to hold a URL that has a variable of its own. Here is an idea of what I'm trying to do: href="javascript:...
6
by: Eric Johnston | last post by:
I want the visitor to enter three numbers on the page and then click a button "generate image" which will I hope cause a generated gif image to be displayed alongside on the page. This involved...
9
by: Max | last post by:
I'm new with Javascript and can't seem to figure out what I'm doing wrong here as I'm not able to pass a simple variable to a function. In the head of doc I have: <script...
6
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an...
3
by: jsdeveloper | last post by:
Hi, I just started programming in javascript, and I'm having a problem passing variables between javascript and asp code in .asp page. Can you please help? I've given the sample code below. ...
1
by: johnjsforum | last post by:
Buddies, I have a web page to create HTML buttons dynamically as in the “formDivColorPicker” function ////////////////////////////////////////////////////////////////////////////////////...
3
by: q-rious | last post by:
Hello All, 1. I would like to pass some variables (x and y below) from Javascript to PHP, process them in PHP, and return some other variables (a abd b) back to Javascript. --(x,y)--...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.