Solved

Passing variables between HTML pages using Javascript

Posted on 2000-03-03
6
413 Views
Last Modified: 2008-03-03
Can someone please tell me how to pass variables between pages using Javascript. For example if i define a variable "Score" in a file called 'page1.html' how can I get that variable into 'page2.html'.
0
Comment
Question by:sj_excel
6 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2581582
you might have to use a CGI program of some kind to act as a glue between these pages. Without this glue both these HTML files are 2 individual documents without any way to talk toeach other.

i dont think javascript would work as that glue here.
0
 

Expert Comment

by:hakimus
ID: 2582231
If there i not very much variabels, you can use "cookies".
See javascript,internet.com for "copy/paste"ecxamples!!

Regards,
0
 

Expert Comment

by:jocas
ID: 2583008
You could also pass information in the URL, although I'm not sure how many browsers support this for client side JavaScript.
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 8

Expert Comment

by:jbirk
ID: 2583107
Using location.search is supported since javascript 1.0, so that would be netscape 2.0 and IE 3.0.  To send the info this way you'd need to pass it like this:
document.location="whatever.html?"+escape(Score);

Then in the receiving page,
Score = location.search; // grabs the search string
Score = unescape(Score.substring(1)); // removes the ? at the beginning, and unescapes the variable

To use cookies is a little more complex, but is more behind the scenes (the search way shows up in the location bar where the user can see the value getting sent)

-Josh
0
 

Expert Comment

by:jocas
ID: 2583712
If you want code for passing parameters using location.search, check out PAQ

www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=10196601 
0
 

Accepted Solution

by:
rviswa earned 50 total points
ID: 2630073
If you want a secure transmission of data, then you should POST the form. So that the values will be sent in the HEADER. If the site is UNSECURED, you can pass the value using QueryString.

Now, to answer your question: Use a HIDDEN text box in the first form and update the variable's value in it. When you POST this form and loading the next PAGE( for example Page2.asp), you can get this value from Request.Form().

This WILL work. Let me know how it is going. Have fun.
E-Mail:rviswa@yahoo.com
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question