Ketan Patel

User Poll Script using Ajax and PHP

User Poll Script using Ajax and PHP

In this tutorial, we'll be creating an Ajax Poll Script that displays the results with colored images using PHP and Ajax.

This is a very simple Ajax poll script. Poll results will be displayed on the current page without moving to another page. The result of the poll is stored in a separate text file and results will be displayed based on the values stored in this file.As the data is saved in flat file it  does not require any database



function Vote(int)
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  {// code for IE6 and IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  if (xmlhttp.readyState==4 && xmlhttp.status==200)

<div id="poll">
Do you like PHP Dev Zone?</h3>
<input name="vote" onclick="Vote(this.value)" type="radio" value="1" />

<input name="vote" onclick="Vote(this.value)" type="radio" value="0" />


<td><img alt="poll" height="20" src="pollyes.jpg" width="<?php echo(100*round($yes/($no+$yes),2)); ?>" />
<td><img alt="poll" height="20" src="pollno.jpg" width="<?php echo(100*round($no/($no+$yes),2)); ?>" />
<td><a href="">Back To Tutorial</a></td></tr>

Below are the snapshots of the script output.

User Poll Script using Ajax and PHP

User Poll Script using Ajax and PHP

ketan patel

About Ketan Patel -

I have developed a wide range of websites using CorePHP, Opencart, CakePHP and CodeIgniter including sites for startup companies and small businesses. Apart from my blogging life, I like to read Novels, Listening music and Net surfing.

Subscribe to this Blog via Email :