472,352 Members | 1,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,352 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 11324
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. ...
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...
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...
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...
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...
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...
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...
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...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.