Pin Me

HTML Tutorial: Create Your Own Web Polls

written by: S. R. Obbayi•edited by: Amy Carson•updated: 9/21/2010

Web polls are a great way to get user feedback on specific issues and to allow them to respond on precise points. However, setting up one is not very straightforward. Read on to find out how to write HTML code for web polls.

  • slide 1 of 4

    Introduction

    To develop a web poll you need to keep in mind that there should be four basic parts that should be included in any piece of HTML code for web polls. The first of these basic parts is the question that will be asked to the users.

    The second is a multiple choice list of questions to choose from where the users should be restricted to choosing only one question.

    The third item that must always appear in a HTML web poll is obviously a way of submitting the user answers. This is mostly achieved in the form of a HTML push button. There should then be a part of the web poll that is responsible for showing the results back to the user.

    Finally you need a place to save the results of the HTML web poll. This would usually be a database stored on a web server.

  • slide 2 of 4

    The HTML Code

    pollform Let us get started with writing the HTML code for web poll. This will consist of a web form and a result panel. To create the web form you use standard HTML tags to create the form to hold the list of radio buttons that will represent the answers. Finally there should be a panel which will hold a list of the answers as placed by the other users in the form of percentages.

    This is some sample HTML code for displaying the form.

    <FORM METHOD="post" ACTION="server_file_to_process_form_data">

    <B>Poll</B><P>

    <B>Do you like web polls?</B><P>

    <INPUT TYPE="radio" NAME="answer" value="1">Yes I do<BR>

    <INPUT TYPE="radio" NAME="answer" value="2">No, I do not<BR>

    <INPUT TYPE="radio" NAME="answer" value="3">I dont know<BR>

    <INPUT TYPE="radio" NAME="answer" value="4">depends on the question<P>

    <INPUT TYPE="submit" name="submit" value="Submit">

    </FORM>

    This is as simple as it gets. Then there is the code template that represents the answers in the form of percentages based on the collective answers of the users. Take note that the HTML code below needs to be loaded dynamically based on the actual answers so that it can reflect the actual results.

    poll reslts <DIV>

    <B>Poll Results</B><P>

    <UL>

    <LI><B>Yes I do</B> 50%

    <LI><B>No, I do not</B> 5%

    <LI><B>I dont know</B> 20%

    <LI><B>Depends on the question</B> 25%

    </UL>

    </DIV>

  • slide 3 of 4

    Putting It All Together

    Unfortunately, as beautiful as the HTML code above looks, it will be pretty much non-functional without the help of some server-side code to process the data collected. The reason is that HTML forms are designed to collect data but not to process it.

    To process the data collected through the web poll, you need to collect the data on the server and increment a counter stored in a database. Get the averages of the counters for all answers then respond with percentages of popularity of each question. This processing can be done on any web server in a language that is compatible with that particular web server. Regardless of the language used, the general process is standard. Here is some sample pseudo code the illustrates what happens when the user submits the web poll.

    if( Success in Opening database ){

    temp_id = ID from web form

    Enter database and Extract all IDs

    while( ID <= 4){

    array_count = current vote count from database

    If(ID == temp_id){

    array_count = array_count + 1

    }

    ID = ID +1

    }

    ID = 1

    while(ID <=4){

    foreach(ID)

    {

    vote_count_percentage_array = (current vote count / total vote count)x 100

    ID = ID +1}

    ID = 1}

    while(ID <= 4){

    print “<LI><B>$Answer$</B> vote_count_percentage_array[ID]"

    ID = ID +1}

    }else{

    General Poll failure}

  • slide 4 of 4

    Conclusion

    There are several variations to the way you can create web polls. Some include improving the appearance of the web poll by using JavaScript effects, graphics and dynamic data exchange using Ajax. Whichever method you choose to use, the methods described in this article form the basis for HTML code for web polls.