Click to See Complete Forum and Search --> : Passing variables from one page to another
drn33
02-16-2003, 07:15 PM
I'm not sure if this can be done with Javascript, so hopefully someone here will know for sure. I have a page with 100 products on them. Clicking on any of them will go to a page that looks the same, except for the image, a two sentence text description and the code on a button (to an external shopping cart). When the user clicks on a product, I'd like them to go to one page and have the image, text and code on the button load based on the item clicked on the previous page (rather than create 100 html pages). The rest of the interface will stay the same. Can I do this with Javascript? (the hosting service does not offer ASP or JSP, or I'd be trying that route). I'd also like to avoid a pop-up window, which would obviously be easier to pass variables from.
Any help, even partial would be greatly appreciated.
Thanks, Darren
2 peachy
02-16-2003, 07:17 PM
I am not sure, but think you need to make the variables global
geuis
02-16-2003, 07:30 PM
you can use temporary cookies or you can submit the info through a POST method in a <form>.
Geuis
Nedals
02-16-2003, 07:33 PM
There are a couple of ways that come to mind.
1. Post your data using 'get', then collect the data from the page URL.
2. Use Cookies (probably easier)
The new page would then be constructed based on the URL or Cookie data using document.write.
geuis, wasn't trying to upstage you. Your post was not there prior to mine. Great minds think alike :-)
drn33
02-16-2003, 08:08 PM
Great information, all of you. I hadn't thought of the cookie method, and honestly haven't created cookies with javascript before. Any link ideas for a useful tutorial on generating cookies for what I want to do?
I looked up the post method and extracting from a URL, but it mentioned that I can't use special characters, and the shopping cart code is laden with special characters, so that migh not be the easiest way to go.
One more thing. If I use cookies, should I dynamically generate the whole page with document.write, or just the 3 areas that need it?
Thank you very much for your help!
Darren
Nevermore
02-17-2003, 04:48 AM
An even easier way would be to call the pages from a database and template using something like PHP and SQL. Does your server support anything like these? The advantages would be:
Would work even if user had cookies turned off.
Less coding
Easier to update.
drn33
02-17-2003, 10:00 AM
Thanks for the suggestion on PHP or SQL, I'll check and see. The web host is yahoo, and I know the server is Unix. Plus I'm not sure what you get for the package my client is on. But I will ask.
Thanks, Darren
khalidali63
02-17-2003, 10:02 AM
I've posted a solution earlier for this thread
http://forums.webdeveloper.com/showthread.php?s=&threadid=4326
You can use it as well.
It demonstrates the passing of varaibles to the same page but you can send them to any other page
cheers
Khalid