Download AJAX poller script

Demo

Bookmark and Share

Licensing

This script is distributed under the LGPL open source license.
Commercial licenses are also available. Some of these licenses also includes personal e-mail support for up to 1 year.

Download script

You can download the entire script from this Zip file.

Configuration

PHP and mySql required

This script requires that you have PHP installed on your server and access to a mySql database.

Files included in package

  • ajax-poller.html = Main HTML file. Contains some HTML code and some PHP code. You will find the code for the poller between the comments <!-- START OF POLLER --> and <!-- END OF POLLER -->.
  • ajax-poller-cast-vote.php = This file is called by ajax when someone casts a vote. This file updates the database and returns vote results as XML back to ajax-poller.html
  • dbConnect.php = File included by ajax-poller and ajax-poller-cast-vote.php. This file connect the scripts to your database
  • js/ajax-poller.js = Main Javascript file for this script.
  • js/ajax.js = Ajax (SACK library).
  • css/ajax-poller.css = Cascading style sheet for the poller
  • images/* = images used by the script
  • createDbTables.php = Installation file. This file creates the default database tables you need for this script. Just put in connection and data and execute the file in your browser

Installation

This is a step by step guide on how to configure this script

  1. Modify dbConnect.php. Insert your dbName, username and password. You may have to create a new database.
  2. Edit createDbTables.php. Insert your dbName, username and password and execute the script in your web browser
  3. Now, try to open ajax-poller.html in your web browser

Javascript variables

You will find some variables at the top of ajax-poller.js which you could modify:

var serverSideFile = 'ajax-poller-cast-vote-php';
var voteLeftImage = 'images/graph_left_1.gif';
var voteRightImage = 'images/graph_right_1.gif';
var voteCenterImage = 'images/graph_middle_1.gif';

var graphMaxWidth = 120; // It will actually be a little wider than this because of the rounded image at the left and right
var graphMinWidth = 15; // Minimum size of graph
var pollScrollSpeed = 5; // Lower = faster var useCookiesToRememberCastedVotes = true;

  • serverSideFile = Path to the PHP file that is called by ajax.
  • voteLeftImage, voteRightImage and voteCenterImage = Path to the graph images
  • graphMaxWidth = Max width of graph
  • graphMinWidth = Min width of graph
  • pollScrollSpeed = Speed of animation. Lower value = faster animation
  • useCookiesToRememberCastedVotes = If set to true, use cookie to prevent user from casting more than one vote

Comments

hm
ajax-poller.html is displaying the following in the survey box rather than the survey - any ideas... thanks!

".$inf["pollerTitle"]."

"; // Output poller title $resOptions = mysql_query("select * from poller_option where pollerID='$pollerId' order by pollerOrder") or die(mysql_error()); // Find poll options, i.e. radio buttons while($infOptions = mysql_fetch_array($resOptions)){ if($infOptions["defaultChecked"])$checked=" checked"; else $checked = ""; echo "
".$infOptions["optionText"]."

"; } } ?>
hm at 12:37AM, 2011/05/17.
Admin comment
DHTMLGoodies
HM,

Inside ajax-poller.html change all PHP short tags <? to <?php.

If that doesn't help, change the name of the file to ajax-poller.php
DHTMLGoodies at 12:36PM, 2011/05/18.
Colleen
I am having the same issue as the user above. I tried both your tips. Changing
Colleen at 07:50PM, 2011/05/18.
Colleen
Sorry for the above. What I was saying is that neither tip works. Changing the ? tags ?php (actual tag symbol omitted) tags in the html file still returns all that code in the right hand box. Changing the file to .php returns nothing in the right hand box but the vote button.
Colleen at 07:55PM, 2011/05/18.
alper
$pollerId = 3; // Id of poller

change this line;

$pollerId = 1; // Id of poller : sample db hasnt a poll ided by 3 :)
alper at 10:14PM, 2011/05/30.
khalid
Great work.
also here you can find the DEMO and pool script here, http://www.webfreescripts.com/?p=1380
its easy and interesting.
khalid at 03:59PM, 2011/06/16.
vikxit
<a href="#comment474">hm wrote:</a>
ajax-poller.html is displaying the following in the survey box rather than the survey - any ideas... thanks!

".$inf["pollerTitle"]."

"; // Output poller title $resOptions = mysql_query("select * from poller_option where pollerID='$pollerId' order by pollerOrder") or die(mysql_error()); // Find poll options, i.e. radio buttons while($infOptions = mysql_fetch_array($resOptions)){ if($infOptions["defaultChecked"])$checked=" checked"; else $checked = ""; echo "
".$infOptions["optionText"]."

"; } } ?>


Set a password to your database
vikxit at 01:13PM, 2011/07/11.
A. Razzaghi
Hi dears. I've done everythings that u told in this page, but there are some problems,
1. When I've execute createDbTables.php in my browser it give me this :

"Forbidden
You don't have permission to access /ajax-poll/createDbTables.php on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
"
But i maked the options in mysql manual.

2. When opening the page ajax-poller.php , poll box is empty and in box is just vote button.

why am i do ?
sorry for my english.

Sincerely.
A. Razzaghi at 11:59AM, 2011/07/21.
A. Razzaghi
<a href="#comment720">vikxit wrote:</a>
<a href="#comment474">hm wrote:</a>
ajax-poller.html is displaying the following in the survey box rather than the survey - any ideas... thanks!

".$inf["pollerTitle"]."

"; // Output poller title $resOptions = mysql_query("select * from poller_option where pollerID='$pollerId' order by pollerOrder") or die(mysql_error()); // Find poll options, i.e. radio buttons while($infOptions = mysql_fetch_array($resOptions)){ if($infOptions["defaultChecked"])$checked=" checked"; else $checked = ""; echo "
".$infOptions["optionText"]."

"; } } ?>


Set a password to your database




No. if it changing to .php it will be ok.
A. Razzaghi at 12:01PM, 2011/07/21.
Hakan
if there are two html form in the page, poll doesnt work. help me pls.
Hakan at 07:39PM, 2011/07/30.
alihuc
Thanks
but i have a problem, it doesn't work with other <form> in page...
alihuc at 05:10PM, 2011/09/08.
Karma
It worked!
1) Change the database user and pass from dbConnect.php and createDbTables.php

2) Change the name of the file ajax-poller.html to ajax-poller.php

3) Change all PHP short tags <? to <?php.

4)change the line $pollerId = 3;// Id of poller
TO
$pollerId = 1;// Id of poller : sample db hasnt a poll ided by 3 :)

Hope this will help! I would appreciate if someone could help me to restrict the voting to one time only (let's say once in a day)
Thankyou
Karma at 08:06AM, 2011/11/19.
Karma
To restrict voting one time only
ajax-poller.js line 38
useCookiesToRememberCastedVotes = true;

Very Nice. Thank you Admin
Karma at 08:18AM, 2011/11/19.
Ouattara
Thx kARMA!!!
Ouattara at 08:11AM, 2012/02/02.
kishor
Hello, My problem is with checking the cookie for each of the poll already voted [m looping through the table and print out all the polls in a single page..] , the cookie is checked only for the last poll and not for those before.. for eg: if i voted for the polls with id 1,2,3 .. the cookie is checked for has it been voted for id 3 and not 1 or 2.. plz help
kishor at 07:24AM, 2012/03/02.
Abhinandan Srivastava
If i checked radio button then not give result.only display
Getting poll results. Please wait...
Abhinandan Srivastava at 09:00AM, 2013/03/06.
ABDELYAZID BEKRI
Hi everyone,

I need to display the label and the graph in the same line
How to do

Thanks
ABDELYAZID BEKRI at 02:41PM, 2014/01/25.
Ramkumar
HI,

I need to display results only. how can i do that
Ramkumar at 02:42AM, 2014/01/28.

Post your comment

Don't have an avatar? Create one at Gravatar.com.

Confirmation code:

Go to cbolson.com


About/Contact | A good idea? | Submit a script | Privacy notice
© 2005 - 2014 dhtmlgoodies.com