Writing Poll Code Manually
If you would prefer not to use the Poll Creator, you can create a poll by writing the code yourself. If you would like to create a poll this way, or learn more about how the poll code works, read this tutorial.
When writing a journal entry, you can tell the LiveJournal servers that you want to start a poll by inserting the <lj-poll> tag. When the server parses this tag, it knows to display a poll based on the questions (<lj-pq>; "poll questions") and possible answers (<lj-pi>; "poll items") you provide.
When creating a poll, you must be very careful to provide a closing tag for every opening tag you insert, or the poll will not function correctly.
A very basic poll would look like this:
<lj-poll>
<lj-pq type="radio">
What is your name?
<lj-pi>Sir Lancelot of Camelot</lj-pi>
<lj-pi>Sir Robin of Camelot</lj-pi>
<lj-pi>Arthur, King of the Britons</lj-pi>
</lj-pq>
</lj-poll>
Some poll tags have attributes that you can use to provide more information. For example, a poll can be named by including the "name" attribute in the lj-poll tag, like this:
<lj-poll name="My First Poll">
<lj-poll> (beginning poll tag)
Here is an example of a complex <lj-poll> tag:
<lj-poll name="The Bridge of Death" whovote="friends" whoview="all">
(This starts a poll named the "The Bridge of Death", where only the people on your friends list can vote. Anyone can see the results.)
<lj-pq> (poll question)
When writing a journal entry, you can tell the LiveJournal servers that you want to start a poll by inserting the <lj-poll> tag. When the server parses this tag, it knows to display a poll based on the questions (<lj-pq>; "poll questions") and possible answers (<lj-pi>; "poll items") you provide.
When creating a poll, you must be very careful to provide a closing tag for every opening tag you insert, or the poll will not function correctly.
A very basic poll would look like this:
<lj-poll>
<lj-pq type="radio">
What is your name?
<lj-pi>Sir Lancelot of Camelot</lj-pi>
<lj-pi>Sir Robin of Camelot</lj-pi>
<lj-pi>Arthur, King of the Britons</lj-pi>
</lj-pq>
</lj-poll>
Some poll tags have attributes that you can use to provide more information. For example, a poll can be named by including the "name" attribute in the lj-poll tag, like this:
<lj-poll name="My First Poll">
TAGS AND THEIR ATTRIBUTES
<lj-poll> (beginning poll tag)
- name="..."
- Labels the poll with a descriptive name
- whovote="all,friends"
- Specifies who is allowed to vote in your poll. Options include any LiveJournal user (all), or just the people listed as friends (for personal journals) or members (for community journals) of the journal in which the poll is posted (friends). The default is all.
- whoview="all,friends,none"
- Specifies who is allowed to see which user chose which answer for the poll. Options include any LiveJournal user (all), which is the default; just the people listed as friends (for personal journals) or members (for community journals) of the journal in which the poll is posted (friends); or no one except the journal owner of the journal in which the poll was posted (none). Any user who can see the entry that the poll resides in can see the aggregate statistical data (percentages and bar graphs).
Here is an example of a complex <lj-poll> tag:
<lj-poll name="The Bridge of Death" whovote="friends" whoview="all">
(This starts a poll named the "The Bridge of Death", where only the people on your friends list can vote. Anyone can see the results.)
<lj-pq> (poll question)
- type="radio"
- Each item listed as a possible answer will have a radio button next to it, which means that people can only select one possible answer. At least one <lj-pi>possible answer</lj-pi> must be specified for each "radio" question.
- type="check"
- Each item listed as a possible answer will have a check box next to it, which means that multiple choices may be selected. At least one <lj-pi>possible answer</lj-pi> must be specified for each "check" question.
- type="drop"
- Each item listed as a possible answer will be displayed in a drop-down selection box, so that only one answer can be chosen. At least one <lj-pi>possible answer</lj-pi> must be specified for each "drop" question.
- type="text"
- Displays a box that allows a person to freely type in a string of text as their answer. When a text input question is declared, there are no possible choices to be displayed (<lj-pi>).
- If a question is of type text, two additional attributes are possible, "size" and "maxlength". Example, size="30" will display a 30 character wide input box, while maxlength="50" will limit the voters' answers to 50 characters each.
- The limit for the "size" is 100. The limit for "maxlength" is 255.
- type="scale"
- Displays separate numeric options based on the information specified. Voters are typically expected to be ranking or rating something, based on a number scale given.
- If absolutely no attributes (discussed below) are specified, the poll will display a scale of choices from 1 to 10.
- If a question is of type scale, three additional attributes are possible: "from", "to", and "by", which define the range of the question. "from" is the beginning number, "to" is the finishing number (which must be greater than the "from"), and "by" is the number of units in between each choice; this value must be 1 or greater.
- For example, if you want to make one of your questions "How old is old?" and wanted to include choices between 40 - 100, but only want choices in increments of 5 (eg 40, 45, 50, etc), you would enter <lj-pq type="scale" from="40" to="100" by="5">.
- Scale type questions must be limited to 20 possible choices per question. For example, a scale from 1 to 100 by increments of 5 is permitted; a scale from 1 to 100 by increments of 1 is not.
- If you use the scale option, the LiveJournal server is able to compute interesting numerical statistics on the way people have voted, such as the median and the average.
THINGS TO REMEMBER WHEN WRITING POLL CODE
- Each tag needs an appropriate closing tag.
- Each <lj-pq> requires a "type" attribute.
- The question text must follow immediately after the <lj-pq> tag.
- <lj-pi> tags are for radio, check, and drop questions only. All possible answers are wrapped in <lj-pi> tags </lj-pi>. They are to be inserted after the question's text, but before the question's closing </lj-pq> tag.
- Poll tags need to be nested correctly in order to work. For example, you must close each answer or question before you start a new one.
- If you insert a line break inside a poll tag, it will not be automatically converted to an HTML line break (<br>), and the line break (<br>) and paragraph (<p>) tags are not allowed in polls.
