That's what I want to do - but that ID is only available in the PHP script/session variable from a mysql query
Main Topics
Browse All TopicsHi,
I have a polling system on my website which is located on a sidebar that is included with include_once. I currently have it set up so that once the user has taken part in the poll, javascript sets a cookie on their machine and then the php checks whether this cookie is set and then displays the poll choices, or the results of the poll depending on this cookie.
My problem is that i want the cookie name to be equal to the unique ID of the poll so that if a new poll is coded then the cookie wont be set and the user will then get the poll choices again. As i am setting the cookie with javascript (I cant do it in the php file as data has already been sent to the browser) I cannot change the cookie name based on the poll ID as this information is only available in the php script. Is there a way around this, or a better way to do a polling system?
Many thanks.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I am not sure what you may be indicating with your response of -
"This unfortunately won't work I dont think as the javascript is in an external .JS file so it wouldn't recognise the PHP tags surely"
Are you saying you need an entire NEW Poll System, since you don't see a way to work this in your current one. For me and maybe others, I can not tell what your current poll system may or may not can do, or what parts of it can be made to do what you want to do. You give so little info about it.
you are not wrong about that, it will not work in the "FIXED" external JS file, however Airspray has shown you a framework for a "dynamic" changeable JS file that is a PHP script that does the javascript AND has PHP variables written into it. But you may not want the trouble of redoing your external JS file as a PHP script. So I do not understand why you can not set your own cookies with JS and PHP as show above, and not use the external JS for cookies, since you seem to not want to deal with rewriting the external JS. You can also have more than one cookie, you can use the external JS cookie AND add your own cookie (PHP) for the view on your page or you can change the existing cookie, and add data to it. Can you tell use more about your code, do you have any JS variables that have the external cookie name or data?
Business Accounts
Answer for Membership
by: AirsprayPosted on 2009-09-03 at 12:02:10ID: 25253808
How about setting a variable to the cookie variable like
Poll_123_Answered=1
123 being the poll's ID.