On Facebook, when you make a question, users can make their own answer to the poll. I was wondering how to do exactly that. How do I make a poll where users can make their own option?
So you add an extra radio button at the bottom of the form, with an <input type=text> instead of a <label>. You will want some javascript to select the bottom radio button when the text control receives focus.
Then on the backend, if the extra radio button was selected, instead of incrementing the vote count for that answer, you create a new answer in the database with a vote count of 1.
I assume you have your answers stored in a table like the following (pseudo-sql, my sql is rusty):
CREATE TABLE answers (
question_id INTEGER NOT NULL,
answer_id INTEGER NOT NULL,
answer_total_votes INTEGER DEFAULT 1,
answer_text TEXT NOT NULL,
PRIMARY KEY (question_id, answer_id)
)
5 comments
[ 6.2 ms ] story [ 16.4 ms ] threadThen on the backend, if the extra radio button was selected, instead of incrementing the vote count for that answer, you create a new answer in the database with a vote count of 1.
I assume you have your answers stored in a table like the following (pseudo-sql, my sql is rusty):