473,881 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing variables from Javascript to ASP

6 New Member
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 11458
bakpao
21 New Member
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 Recognized Expert Expert
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
ernesto
6 New Member
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("photoI D") -
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 Recognized Expert Expert
Heya, Ernesto.

So the value of the session variable depends on which link the User clicks?
Aug 28 '07 #5
ernesto
6 New Member
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 Recognized Expert Expert
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 Recognized Expert Specialist
Ernesto,

syntax for the URL with a querystring in it should be [html]<a href="ASP2.asp? photoID=234">Cl ick 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 Recognized Expert Contributor
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("PhotoI D") = Request.QuerySt ring("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("i PhotoID") 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
ernesto
6 New Member
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("PhotoI D") = Request.QuerySt ring("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("i PhotoID") 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
3625
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: ----------------------------------------------------------------------- <script language="JavaScript"> function addProcess(addPName,addSProcess,addPIndex) { var addProcessWindow = window.open('second.asp','mywindow','width=400,height=200');
3
14968
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) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
5
2181
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 window and call the form. In this particular instance, a city name is what I have to pass to the form Chapter.htm. <html> <head>
2
2186
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: newWin('/vcrc/exitvcrc.jhtml&newURL=http://www.something.net/default.asp?sponID=ETC','NowLeaving','420', '200', 'no', 'auto','no');" So, pretty much, the page I'm sending the variable to think there's two variables (newURL and sponID), but...
6
1655
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 a php page elsewhere which does all the computing of the gif image. I can make this work successfully by using a static call like: <img src="test12.php?a=15&b=65&c=33000" width="200" height="200"> How do I write javascript to allow the visitor...
9
2177
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 type="text/javascript"> function radioenable(value) { document.forms.search.elements.value.disabled=false;
6
5586
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 object collection and stanrd using it it starts to fall apart. Clearly there is something about javascript's usage of passing "By ref" that i am not getting. i have had a look on the web and found some examples, but i cant see why my code does not...
3
2125
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. ---------------------------------------------------------------------------------- <script src="http://www.aurumtech.com/domain_str.js" type="text/javascript"></script> <script type="text/javascript"> var email_str = "joe@example.com" var...
1
2288
by: johnjsforum | last post by:
Buddies, I have a web page to create HTML buttons dynamically as in the “formDivColorPicker” function //////////////////////////////////////////////////////////////////////////////////// version 1 : using global variables ////////////////////////////////////////////////////////////////// var _textField, _divColorPicker; // global vars window.onload = function() { _textField = document.getElementById('htxaMessage'); // fill...
3
2300
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)-- --(a,b)-- 2. The variables x and y are not known to HTML directly, so I can not pass them to PHP as:
0
9929
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11102
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10818
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10403
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7112
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5781
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5978
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3225
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.