jQuery Plugin – jPoll

December 13, 2009

jPoll, with an accompanying nettuts+ screencast, provides a ‘poll’ widget which can be used to ask your visitors a brief question. The widget will create and render a form inside a designated container and then monitor the form for submission.

When the form is submitted,the results are passed to a backend file which processes the response (I used PHP and MySQL, although other languages and database servers are available). The widget is just the frontend of the application, you must supply the backend.

Once the visitor’s choice has been saved, the results of the poll are then passed back to the widget as a JSON object and the widget displays the results using nice animations.

Example

Features

The first release of jPoll comes with the following features:

  • Automatic error message for submission before choice is made
  • AJAX sending and receiving of selection and results
  • Built-in result animations

Usage

All you need to do on the webpage is supply a container element with an id:

<div id="container"></div>

Then in your script, just call the jPoll constructor supplying a literal configuration object containing the customised properties:

$("#container").jPoll({ ajaxOpts.url: "myBackend.php", groupIDs: ["A Question", "Another Question", "Etc..."] });

All of the properties have defaults, but some are fairly generic. The config section below shows all of the properties and their default values.

Note that this is just the front-end – you must have a database setup to store the results in and you need an accompanying PHP script that gets and set the results in the database.

Config

var config = {
  ajaxOpts.url: "a string" //defaults to "poll.php"
  groupName: "a string" //defaults to "choices"
  groupIDs: ["an array"] //defaults to ["choice0", "choice1", "choice2", "choice3", "choice4"]
  pollHeading: "a string" //defaults to "Please choose your favourite:"
  rowClass: "a string" //defaults to "row"
  errors: true || false //defaults to true
}

$("#container").jPoll(config);

Leave a Reply

  • jQuery UI 1.7: The User Interface Library for jQuery

    jQuery UI 1.7

    Learn the latest version of jQuery UI with a detailed, step-by-step approach£29.99£23.79!Read more
  • jQuery UI 1.6: The User Interface Library for jQuery

    jQuery UI 1.6

    If you need to use jQuery 1.2, this book will show you how to leverage jQuery UI 1.6£29.99£23.79!Read more
  • Learning the Yahoo! User Interface Library

    Learning YUI

    Discover how to use version 2 of the YUI to it's full potential£27.99£23.79!Read more