

Ask HN: Difficult Form Problem - Aeiper

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?
======
mooism2
What are you having trouble with? The html? The backend? Something else?

~~~
Aeiper
I do not know anything at all about how to do this or start it.

~~~
mooism2
Would you know how to do this if poll respondents weren't allowed to add their
own answers?

~~~
Aeiper
Yes

~~~
mooism2
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)
      )

